Cool Guy Yo
Cool Guy Yo

Reputation: 6110

Validation on keyup on onchage not working for meteor js

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

Answers (1)

Adam Wolski
Adam Wolski

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

Related Questions