0

So I have a fairly large form with two different sections. Both sections start off as hidden:

<fieldset class="section1" style="display:none">
//...input fields
</fieldset>
<fieldset class="section2" style="display:none">
//...input fields
</fieldset>

The sections are shown depending on which radio button the user selects. This all works great until I get to validation. How could I go about validating the form using the jQuery/Validation plugin but have it only validate the section that is showing?

Note: There are other sections that are always shown so I'd rather not have two separate forms.

1 Answer 1

5

You could ignore validation rules for elements inside the hidden section of your form:

$('#myForm').validate({
    ignore: 'fieldset:hidden :input',
    ...
});
2
  • 1
    Simple. Elegant. Worked. Thank you. Jun 6, 2011 at 17:50
  • 1
    or ignore: ':not(:visible)' Feb 19, 2013 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.