Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset/remove classes from a form after jquery validator use inside modal

I am basically loading content into a bootstrap modal, editing the information and validation it using jquery validator, then submitting it with an ajax request. Everything is working well so far, until I click on another item where the validation classes are still appearing. My question is, is there a way of removing the validator classes after closing the bootstrap modal? Please help

like image 791
Maff Avatar asked Sep 20 '25 12:09

Maff


2 Answers

There is a resetForm method you can use to set the state of the validator.

// on load of your dialog:
var validator = $('#myForm').validate();
validator.resetForm();
like image 167
Rory McCrossan Avatar answered Sep 23 '25 02:09

Rory McCrossan


If you are using bootstrapvalidator, the following code will help to get rid of error elements

$("#editModal").on('hidden.bs.modal', function () {

        //Removing the error elements from the from-group
        $('.form-group').removeClass('has-error has-feedback');
        $('.form-group').find('small.help-block').hide();
        $('.form-group').find('i.form-control-feedback').hide();

    });
like image 37
Senthil Kumaran Avatar answered Sep 23 '25 02:09

Senthil Kumaran