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

2019-09-06 06:50发布

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条回答
贼婆χ
2楼-- · 2019-09-06 07:33
$('#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);
});
查看更多
登录 后发表回答