开发者

jquery validation only for visible controls

开发者 https://www.devze.com 2022-12-12 08:32 出处:网络
I am using jquery validation for required field vaidation. $(\"#registerform\").validate(); This fires for the controls which are hidden too.

I am using jquery validation for required field vaidation.

$("#registerform").validate();

This fires for the controls which are hidden too.

For ex.: When the user selects Others option in How you find us? in register form, its required to fill the textbo开发者_运维问答x for others option.

But this fires even when the control is hidden.

How to do it in jquery validation?


I haven't used the jQuery validation before but according to the doco there's an ignore field that you can pass a jQuery selector to. By using the :visible selector you should be able to do this.

I believe this is what you're after

$("#registerform").validate({ignore:":not(:visible)"});


You may try to add :visible to the selector itself:

$("#registerform :visible")


Please also try this way

 if ($(#registerform).is(":visible")) {
      $(#registerform).validate();
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号