jQuery 验证插件不验证未显示的字段

发布于 2024-12-25 02:03:51 字数 296 浏览 4 评论 0原文

我发现了这个问题,但它是在2009年写的,大概是从那时起他们已决定默认忽略隐藏字段...有人知道我如何验证我的隐藏字段吗?

我有一个自定义的 invalidHandler 来处理结果,并看到一些奇怪的行为,我现在意识到这是因为我的一些字段被隐藏(使用 display:none)。我有一个选项卡式表单,因此隐藏了一些元素仅供参考。

提前致谢。

I have found this question but it was written in 2009, presumably since then they have decided to ignore hidden fields by default...anyone know how I can validate my hidden fields?

I have a custom invalidHandler to deal with the result and was seeing some strange behaviour, I now realise this is because some of my fields are hidden (using display:none). I have a tabbed form, hence some elements being hidden FYI.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥︴琐丶欲为 2025-01-01 02:03:51

找到了答案...

我开始查看验证器插件代码并发现了这一点:

$.extend($.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden", 
...

所以我将选项“忽略”设置为空字符串并且它有效。我想应该更新文档,因为它没有说明有默认的忽略。

不管怎样,谢谢。

Found the answer...

I started looking at the validator plugin code and came across this:

$.extend($.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden", 
...

So I set the option 'ignore' to an empty string and it works. I guess the documentation should be updated because it doesn't state that there is a default for ignore.

Thanks anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文