Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validation only for visible controls

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 textbox for others option.

But this fires even when the control is hidden.

How to do it in jquery validation?

like image 450
Prasad Avatar asked Nov 26 '09 07:11

Prasad


2 Answers

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)"});
like image 192
fyjham Avatar answered Oct 29 '22 12:10

fyjham


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

$("#registerform :visible")
like image 39
Niki Tonsky Avatar answered Oct 29 '22 13:10

Niki Tonsky