最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Reset validation messages after close Bootstrap modal - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Oct 3, 2016 at 18:16 user6446331user6446331
Add a comment  | 

4 Answers 4

Reset to default 11

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

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

Instead of using reset(), try using jQuery Validate's resetForm():

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

If you able to find the div which have validation messages then you can try this as well, where uploadModal is Modal popup id and uploadErrorMessages is validation message div id.

   $('#uploadModal').on('hidden.bs.modal', function () 
    {
     $("#uploadErrorMessages").css("display", "none");

    });
发布评论

评论列表(0)

  1. 暂无评论