我是 Jquery 新手。我在一个包含 14 个字段的表单中工作
前 7 个字段可见,后 7 个字段根据 div 中的按钮点击切换 现在总共有 7 个字段 是'必需'。 3 来自前 7 个(可见部分)和 4 个来自切换 div。
问题是,当切换 div 可见时,如果我错过 7 个字段中的任何一个,JQuery 的验证插件会显示所需的消息,但同一个插件只检查 3< 的验证/strong> 字段(位于 form 的可见部分)当 div 隐藏时 .
即使表单的部分被隐藏,如何进行完整表单的验证 现在,如果我删除文本框 Address 1 的值并隐藏 Address Part 并单击 SAVE 它不会提示输入 required Address 1 的东西,即使我保留它'required'
最佳答案
可能是jquery.validate.unobtrusive.js
文件中有ignore: ':hidden'
行。只需删除该行即可。
在 1.9.0 版本之后这是默认行为。如果文件中不存在该行(我不确定),您可以通过添加手动修复该行
$.validator.setDefaults({ ignore: [] });
如你所见here
Another change should make the setup of forms with hidden elements easier, these are now ignored by default (option “ignore” has “:hidden” now as default). In theory, this could break an existing setup. In the unlikely case that it actually does, you can fix it by setting the ignore-option to “[]” (square brackets without the quotes).
关于隐藏 'div' 中的 Jquery 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10204024/