![](/img/trans.png)
[英]How to validate a field's input value using regular expression in autoform in meteor on client side?
[英]Manipulating field content on client / server using autoform for meteor
我正在玩Meteor和autoform。
我有一个输入字段(类型为“ time”)作为“歌曲”集合的模式的一部分,该集合强制用户键入语法[num] [num]:[num] [num] 。 这是我的架构:
time: {
type: Number,
label: "Time",
optional: true,
autoform: {
afFieldInput: {
type: 'time'
}
}
}
在单击“提交”之后但在验证之前,我想将字符串 (例如“ 03:45”)转换为秒(数字),以便验证顺利通过。
另外:从数据库读取数据时,我想将其转换回string ,以使其适合作为值的输入字段。
我无法在文档中找到关于autoform,collection2或simple-schema的答案(或者至少不了解它;-)
谢谢你的帮助!
使用自动成型挂钩。 您正在寻找的信息在这里: https : //github.com/aldeed/meteor-autoform#callbackshooks
更具体地说,您正在寻找的是:
AutoForm.hooks({
someFormId: {
formToDoc: function(doc) {
// Called every time an insert or typeless form
// is revalidated, which can be often if keyup
// validation is used.
},
docToForm: function(doc, ss) {
// Called whenever `doc` attribute reactively changes, before values
// are set in the form fields.
}
});
可以在每个挂钩中修改doc,尤其是在将其转到集合时以及从集合中以反应方式将其拉出时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.