简体   繁体   English

取消隐藏时,如何防止jquery验证突出显示我的字段?

[英]How do I prevent jquery validation from highlighting my fields when I unhide them?

On my forms I have numerous optional fields that are only needed if a prior checkbox or radio button value is supplied. 在我的表单上,我有许多可选字段,只有在提供了先前的复选框或单选按钮值的情况下才需要。 To keep the form clean I'm hiding those additional fields until they're needed. 为了保持表格清洁,我将隐藏这些其他字段,直到需要它们为止。

The issue I'm having is when those fields are unhidden they're being highlighted as if they had an error, most likely because they're marked as conditionally required. 我遇到的问题是,当取消隐藏这些字段时,它们会像出现错误一样被突出显示,很可能是因为将它们标记为有条件的。 Is there any way to prevent this from happening so the validation only happens on submit? 有什么办法可以防止这种情况的发生,因此验证仅在提交时进行?

I'm using ExpressiveAnnotations and unobtrusive validation is wiring everything up. 我正在使用ExpressiveAnnotations,并且不干扰用户的验证将所有内容都连接了起来。 My jquery validation config is: 我的jquery验证配置是:

$.validator.setDefaults({
    highlight: (element) => {
        $(element).closest('.form-group').addClass('has-error');
    },
    unhighlight: element => {
        $(element).closest('.form-group').removeClass('has-error');
    }
});

To hide or show the extra fields I've wrapped them in a div and toggle the visibility with a class called hidden . 为了隐藏或显示额外的字段,我将它们包装在div并使用名为hidden的类切换可见性。

I'm sure you've tried using 我确定您已尝试使用

display:block;

instead of 代替

visibility:visible;

in your CSS. 在您的CSS中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止NextGen取消注册我的jQuery版本? - How do I prevent NextGen from deregistering my version of jQuery? 如何使用jQuery验证防止在输入字段中写入url? - How do I prevent writing url's inside my input field using jQuery validation? 如果输入其中一个字段,如何在jquery中删除验证 - How Do I remove the validation in jquery when either one of the fields are entered 验证失败时,如何防止锚标记在javascript中重定向 - how do I prevent anchor tag from redirecting in javascript when a validation fails 如何防止我的平滑滚动jquery函数修改div元素的内容? - How do I prevent my smooth-scroll jquery function from modifying the contents of my div elements? 隐藏后如何取消隐藏一行? - How do I unhide a row after it is hidden? 如何防止我的小数在Jquery中删除? - How do I prevent my decimals to be erased in Jquery? 如何阻止SignalR Chat从控制台进行jQuery调用? - How do I prevent jQuery calls from console for my SignalR Chat? 如何防止jQuery扩展深层复制复制某些自定义属性? - How do I prevent a jQuery extend deep copy from copying some of my custom properties? 在jQuery中,如何防止多次点击多次执行我的代码? - In jQuery, how do I prevent multiple clicks from executing my code multiple times?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM