how to reset form on modal hidden or close? [closed]

南楼画角 提交于 2019-12-11 22:28:25

问题


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);  
        });

回答1:


$('#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);
});


来源:https://stackoverflow.com/questions/26327323/how-to-reset-form-on-modal-hidden-or-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!