twitter-bootstrap Bootstrap 验证器 resetForm

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26670478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 21:47:30  来源:igfitidea点击:

Bootstrap validator resetForm

javascriptjquerycsstwitter-bootstrapjqbootstrapvalidation

提问by Nk SP

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.

我在 Bootstrap 3.3 中使用 bootstrapvalidator
我需要在模态对话框中重置表单。
我使用了正确的方法,但它不适用于模态对话框。

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

JSFiddle

回答by 3y3skill3r

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

回答by Shawn Rebelo

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.

重置表单验证,但不会清除字段。这对我来说很好。为多个客户使用一种表格。访问者更容易将他们的姓名和电子邮件留在那里,但只需重新键入消息。所以我只是清除消息字段。