隐藏 'div' 中的 Jquery 验证

标签 jquery html validation jquery-plugins jquery-validate

我是 Jquery 新手。我在一个包含 14 个字段的表单中工作

前 7 个字段可见后 7 个字段根据 div 中的按钮点击切换 现在总共有 7 个字段'必需'3 来自前 7 个(可见部分)和 4 个来自切换 div。

问题是,当切换 div 可见时,如果我错过 7 个字段中的任何一个,JQuery 的验证插件会显示所需的消息,但同一个插件只检查 3< 的验证/strong> 字段(位于 form可见部分)当 div 隐藏时 This is the normal condition .

即使表单的部分被隐藏,如何进行完整表单的验证 this is condition 2 现在,如果我删除文本框 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/

相关文章:

javascript - 如果之前选择过,则禁用选择选项

javascript - Rails 和 jQuery 有时不工作

javascript - 使用 jQuery 第一次调整大小后,drop 和 resize 似乎不起作用

html - 搜索框上的填充不适用于 IE 和 Bootstrap 菜单栏的 chrome

.net - 单击菜单项时验证 DataGridView

php - mysql - 如果日期不与现有日期重叠,则将日期范围插入日期列

c# - 绑定(bind)到 (Validation.Errors).CurrentItem 不适用于 TextBox(适用于 DataGrid)

jquery - : $ (".elt", $this) 或 $this.find (".elt"); 哪个更快?

jquery - 像 jquery 一样的 firebug 实现

javascript - Python FastAPI : Returned gif image is not animating