Validate only visible fields with jQuery classes


I'm validating a form using jQuery validation.

For that I only add an specific class to the fields ("required","email",etc..).

Ex: <input id="form_linom" class="required" type="text" value="" name="form_linom" size="50">

Since is a big and dynamic form (selections in some fields hide or show other fields) I have problems when submitting the form since validator doesn't permit send the data to the server because is validating also the hidden fields.

The way I add the class to each field is making an array in PHP of all the required fields and then if the field is in that array the class is added.

Please read the question before answer. I'm uncomfortable with those no related and 'easy' answers that only criticize the question. I posted all the code I use to validate. The only other thing that I put was this in the header:


I posted code in, look that the email field is hidden but prevent the form to be sent. I need a general rule that collect all the required fields that are hidden, not only the e-mail field as in the example (In my real form I have 54 fields).

This is simple and you should read up on jquery's documantation on their website. this would fall under selectors. The selectors you need to use are

//1. attribute=value
//2. has attribute
//3. mulitple selotors
$('[attributeName], [attributeName=value]')
//4. visible

so an example to select would be

$('#formID input[minlength]:visible, #formID input[class=required]:visible');

I'm going to guess the selector is going to very long and slow. also knowing the selector i pointless because your using a plugin which needs a form. so if you want this feature you have to change the plugin...a lot!. so find a plug in that does this, write your own, or change your form. This is the rare downside to plugins. sometimes they just dont do what you need.