Reputation: 6110
I have the following code, which works on submit, but I want the valiadtion to be run on keyup on onchange or onblur anything with the input fields changing.
This doesnt work with Onchange paramtter. From 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");
}
});
}
Upvotes: 0
Views: 213
Reputation: 5666
Why don't you trigger validation from template events ?
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");
}
});
}
Upvotes: 1