Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validation giving error with every character entered

I'm using jQuery Validator on a form on my site. It is functioning properly, but every keystroke results in an error:

Uncaught TypeError: Object #<error> has no method 'call' 

I am implementing validation through classes on each field and all that is working properly - required fields, email fields, numbers, etc.. Here is my validate code:

 if(jQuery().validate) {
      //assign to global var for manual validation
      validator = $(".validated").validate({
           errorClass: "help-inline text-error",
           errorElement: "span",
           invalidHandler: function(e, validator) {
                var errors = validator.numberOfInvalids();
                if (errors) {
                     var message = errors == 1
                          ? 'Please fix the indicated field before saving this form.'
                          : 'Please fix the errors on the indicated fields before saving this form.';
                      $(".validation-message").text(message);
                      $(".validation-message").addClass('alert alert-error');
                } else {
                      $(".validation-message").removeClass('alert alert-error').text("");
                }
             },
           onkeyup: true,
           submitHandler: function(form) {
                $(".validation-message").removeClass('alert alert-error').text("");
                form.submit();
             },
           errorPlacement: function(error, element) {
                if(element.parent().hasClass('input-append')){
                     error.insertAfter( element.parent() );
                }else{
                     error.insertAfter(element);
                }
             }
      });
 }

Can anyone see what would trigger that error without impacting functionality?

Cheers!

like image 621
whiteatom Avatar asked Nov 30 '25 16:11

whiteatom


1 Answers

There is no true value for onkeyup option.

By default the field validation is enabled during keyup event. You need to use this option only in two scenarios

  1. To disable validation during keyup event, in that case set onkeyup: false
  2. To customize field validation during keyup

In your case you can just remove the option onkeyup.

like image 176
Arun P Johny Avatar answered Dec 02 '25 07:12

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!