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

Siguza
  • 21,155
  • 6
  • 52
  • 89
Nk SP
  • 822
  • 4
  • 19
  • 37

2 Answers2

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'
                    }
                }
            }
        }
    });
3y3skill3r
  • 964
  • 1
  • 11
  • 35
  • Great! Could u please explain it a bit? – Nk SP Oct 31 '14 at 09: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 '14 at 09: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. – Shawn Rebelo Aug 11 '15 at 18:20
  • Hi @CalebPrenger it is still working: http://jsfiddle.net/sdmomphd/15/ here is demo. What is not working for you? – 3y3skill3r Mar 01 '17 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.

Shawn Rebelo
  • 1,027
  • 11
  • 14