jquery-validation icon indicating copy to clipboard operation
jquery-validation copied to clipboard

resetForm not working

Open chaodongyue opened this issue 11 years ago • 7 comments

in chrome v46,int resetForm() function unhighlight is no work,not remove errorClass. I tracked on line 468 the elements variable is an object,this should be the Array of it. http://jsfiddle.net/1t5nzoq2/

chaodongyue avatar Oct 29 '15 04:10 chaodongyue

Thanks for reporting.

Just to make sure we are talking about the same problem:

  • open http://jsfiddle.net/1t5nzoq2/
  • click SAVE
  • click RESET

-> expected: the form should render as on the initial page load -> actual: form control still has red borders and label still are rendered in red color Can you confirm that?

I get the same problem in FF43. Are you willing to provide a failling unit test?

staabm avatar Oct 29 '15 08:10 staabm

Update: I just found a typo in your Fiddle which seems to be the culprit.

fixed version at http://jsfiddle.net/1t5nzoq2/

this

    unhighlight: function (element, errorClass) {
        $(element).closest('.control-group').removeClass(errorClass).removeClass('has-success');
    },

should be

    unhighlight: function (element, errorClass) {
        $(element).closest('.form-group').removeClass(errorClass).removeClass('has-success');
    },

right?

staabm avatar Oct 29 '15 08:10 staabm

fixed version at http://jsfiddle.net/1t5nzoq2/

should be this instead: http://jsfiddle.net/1t5nzoq2/1/

Arkni avatar Oct 29 '15 14:10 Arkni

whatever ;-)

staabm avatar Oct 29 '15 14:10 staabm

@staabm I initially found the problem appeared in the model of the form, and then found that the form of the page is the case, I think that both sides are the same, so ... Please see my latest code,http://jsfiddle.net/1t5nzoq2/3/

  • open modal
  • click save button
  • close modal
  • open modal again

form control still has red borders and label still are rendered in red color.

chaodongyue avatar Oct 30 '15 03:10 chaodongyue

@chaodongyue it is just a missconfiguration. The modal event you are using only executes after the modal components are already hidden. So for your validation to work, you have two alternatives:

  • Instead of using the modal event "hidden.bs.modal", use "hide.bs.modal";
  • Or overwrite the ignore property with an empty string to the validation configuration, see the code http://jsfiddle.net/1t5nzoq2/5/;

@staabm I don't know if this would be a bug or not, but shouldn't the validation message also be kept, since the ignore property is filtering the input that is hidden?

dkrahn avatar Oct 30 '15 12:10 dkrahn

@dkrahn Thank you very much, I finally know what happened

chaodongyue avatar Oct 30 '15 12:10 chaodongyue