我有以下代码,它适用于提交,但我希望在onchange或onblur上的keyup上运行valiadtion,输入字段会发生变化。
这不适用于Onchange paramtter。来自https://github.com/DiegoLopesLima/Validate
Template.contactSubmit.rendered = function(){
$('form').validate({
onChange: true,
sendForm:false,
valid: function() {
var post = {
email: $('form').find('[name=email]').val(),
name: $('form').find('[name=name]').val(),
question: $('form').find('[name=question]').val(),
found_us: $('form').find('[name=found_us]').val()
};
post._id = Contacts.insert(post);
Router.go('acorn', post);
console.log("valid !");
},
invalid: function (){
console.log("notvalid");
}
});
}
答案 0 :(得分:1)
为什么不从模板事件触发验证?
Template.contactSubmit.events({
'change form': function(event, template) {
validateForm(template.find('form'));
}
});
var validateForm = function(form){
$(form).validate({
onChange: false,
sendForm:false,
valid: function() {
var post = {
email: $(form).find('[name=email]').val(),
name: $(form).find('[name=name]').val(),
question: $(form).find('[name=question]').val(),
found_us: $(form).find('[name=found_us]').val()
};
post._id = Contacts.insert(post);
Router.go('acorn', post);
console.log("valid !");
},
invalid: function (){
console.log("notvalid");
}
});
}