Miguel Flores Miguel Flores - 2 months ago 21
Javascript Question

Reset validation messages after close Bootstrap modal

I have a modal with my inputs, I'm using jQuery.Validate to validate my form on submit, my problem is that when I close the modal and then I open the modal again the messages from validation still there, so my question is, how can I reset or hide those messages when I close the modal?

I tried with this but doesn't work

$('#myModal').on('hidden.bs.modal', function () {
window.alertas.reset();
});


How can I solve this?

Here is a sample code to play with.

Answer

You can use together jQuery and jQuery Validate's resetForm():

$('#myModal').on('hidden.bs.modal', function () {
    $('#alertas').validate().resetForm();
    $('.error').removeClass('error');
});
Comments