victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

Duplicate error message when button is click multiple times #636

Closed 3ncor3 closed 7 years ago

3ncor3 commented 7 years ago

Hi,

When I click the submit button multiple times then the error message will duplicate. How to fix this issue?

update : using jQuery v3.2.1

Thank you

untitled-1

$('#someButton').click(function(){
$.validate({
  form : '#frmDaftar',
  modules:"security",
  errorElementClass:"is-invalid",
  borderColorOnError:"",
  errorMessageClass:"invalid-feedback m-0 p-0",
  onSuccess : function() {      
        //triggger ajax
        return false;
    }

});
});
3ncor3 commented 7 years ago

Well, it seems no answer to my question but I manage to do a "quick and dirty" fix.

Just use the beforeValidation event to remove the <span class="help-block"> element everytime a new validation is initiate.

 $('#form).on('beforeValidation', function() {
      $("span.help-block").remove();
    }); 

Its work only when the submit button is clicked (no error message repeat) but it's still repeat on form blur validation event.

victorjonsson commented 7 years ago

One problem with your setup code is that you apply it every time the button is clicked. The setup function is only supposed to run once.

3ncor3 commented 7 years ago

Can you explain a bit more @victorjonsson? perhaps with example :)

victorjonsson commented 7 years ago

Remove the part where you attach a callback function to the button click event $('#someButton').click It should only be:

$.validate({
  form : '#frmDaftar',
  modules:"security",
  errorElementClass:"is-invalid",
  borderColorOnError:"",
  errorMessageClass:"invalid-feedback m-0 p-0",
  onSuccess : function() {      
        //triggger ajax
        return false;
    }
});
3ncor3 commented 7 years ago

Yeah, my mistake. The button click event is unnecessary.

But, how to fix the error message keep repeated? any tips @victorjonsson ?

Thanks

victorjonsson commented 7 years ago

The problem is that you have applied multiple classes in errorMessageClass. Only a single class name is supported.

Korsario23 commented 1 year ago

One problem with your setup code is that you apply it every time the button is clicked. The setup function is only supposed to run once.

Yes. It was my issue. Thanks!!!