twitter-bootstrap jquery 表单验证无法在页面中使用选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12928331/
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
jquery form Validate wouldn't work using tabs in page
提问by Khaled
So basically I have a simple POST form that is being validated using Validate library from jquery, and it all works fine, but then I used the tabs function from bootstrap and many other libraries to separate the form into two different tabs. The problem now is that validation happens only to the open (visible) tab, regardless the condition of the other input fields in hidden tabs. Any possible suggestions?
所以基本上我有一个简单的 POST 表单,它正在使用 jquery 的 Validate 库进行验证,并且一切正常,但后来我使用了 bootstrap 和许多其他库中的 tabs 函数将表单分成两个不同的选项卡。现在的问题是验证只发生在打开的(可见的)选项卡上,而不管隐藏选项卡中其他输入字段的情况。任何可能的建议?
回答by Miika L.
I think your trouble might be that jquery by default will only validate visible fields. So what you need to do is tell jquery to not ignore your hidden fields (other tabs). This can be done as follows:
我认为您的问题可能是默认情况下 jquery 只会验证可见字段。所以你需要做的是告诉 jquery 不要忽略你的隐藏字段(其他选项卡)。这可以按如下方式完成:
$("#form1").validate({
ignore: ""
});
By default ignore: ":hidden".
See this answer, and this documentation(Options -> Ignore).
回答by Hakan F?st?k
Please see the accepted answer above, it is really helpful.
Just in case of using unobtrusive validation, then the accepted answer will not work, and here is the solution.
请参阅上面已接受的答案,这真的很有帮助。
以防万一,unobtrusive validation接受的答案将不起作用,这是解决方案。
$("#form1").data("validator").settings.ignore = "";

