Reset validation messages after closing Bootstrap modal

I have a modal with my inputs, I use jQuery.Validate to check my form on submit, my problem is when I close modal and then I open the modal messages again from validation, so my question is: how can I reset or hide these messages when closing a modal?

I tried with this but didn't work

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

How can i solve this?

Here is a sample code to play.

+4
source share
3 answers

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

$('#myModal').on('hidden.bs.modal', function() {
    var $alertas = $('#alertas');
    $alertas.validate().resetForm();
    $alertas.find('.error').removeClass('error');
});
+3
source

reset() jQuery Validate resetForm():

$('#myModal').on('hidden.bs.modal', function () {
    $("#alertas").validate().resetForm();
});
+3
var validator = $("#myModal").validate();
$('#myModal').on('shown.bs.modal', function (){
   validator.resetForm();
});
0

Source: https://habr.com/ru/post/1656613/


All Articles