如何重置窗体模态隐藏或关闭? [英] how to reset form on modal hidden or close?

查看:181
本文介绍了如何重置窗体模态隐藏或关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗体在模态,当用户点击提交时,窗体将被验证,如果它包含错误,它将不会提交,所以用户可以点击模态关闭按钮或任何地方关闭模态或隐藏它,然后如果用户重新打开模态,验证css将保持在形式,因为他们以前的,所以问题是,如何我可以重置表单显示为一个清晰的fom没有任何验证css,在这里是我使用的代码,但没有工作:

I have a form in a modal, when the users clicks submit, thea form will be validated, if its contain errors, it will not be submitted, so the user can click on modal close button or anywhere to close the modal or hide it, then if the user re-open the modal, the validations css will be remains in the form as they was before, so the question is how I can reset the form to be displayed as a clear fom without any validation css, here is a code I used, but didn't worked:

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

            $('#newsletter')[0].reset();

             $('#newsletter')
                        .bootstrapValidator('disableSubmitButtons', false)  // Enable the submit buttons
                        .bootstrapValidator('resetForm', true);  
        });


推荐答案

$('#clear-form').on('click', function()
    {
        $('#my-form').find('input:text, input:password, select, textarea').val('');
        $('#my-form').find('input:radio, input:checkbox').prop('checked', false);
});

这篇关于如何重置窗体模态隐藏或关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆