5

I am using bootstrapvalidator with Bootstrap 3.3
I need to reset a form in a modal dialog.
I used the right method but it does not work into the modal dialog.

 $('#emailForm').bootstrapValidator("resetForm",true); 

If I open the modal and insert an email, and then try to reset the form, the validation controls are still there.

JSFiddle

1

2 Answers 2

6

It is simple, you just only need to add

excluded: [':disabled'],

Into validation init.

Example:

    $('#emailForm').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        excluded: [':disabled'],
        fields: {
            email: {
                validators: {
                    emailAddress: {
                        message: 'The value is not a valid email address'
                    }
                }
            }
        }
    });
4
  • Great! Could u please explain it a bit?
    – Nk SP
    Oct 31, 2014 at 9:06
  • 1
    By default, the plugin will not initialize the fields which are disabled, hidden, or not visible. Since the form is placed inside a model which is not visible after loading page, the fields/validators initialized with HTML attributes might be ignored.
    – 3y3skill3r
    Oct 31, 2014 at 9:08
  • But if the form is on the page initially in a modal (coded onto the page), this will not work. You can have coded a modal with a form. But have that be able to be used multiple times (like listings) instead of re-fetching the form each time email or whatever is clicked. But if fetching the form each time, see no reason to "reset" the form. Aug 11, 2015 at 18:20
  • Hi @CalebPrenger it is still working: jsfiddle.net/sdmomphd/15 here is demo. What is not working for you?
    – 3y3skill3r
    Mar 1, 2017 at 14:30
6

I know this is very old.

$("#emailForm").data('bootstrapValidator').resetForm();

Resets the form validation, but will not clear the fields. Which is fine in my case. Using one form for multiple customers. Easier for the visitor to have their name and email left there, but just retype the message. So I just clear message field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.