Jamie Curtis
Jamie Curtis

Reputation: 916

How can I jquery/validation with two section in a form?

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.

Upvotes: 0

Views: 213

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039298

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

$('#myForm').validate({
    ignore: 'fieldset:hidden :input',
    ...
});

Upvotes: 5

Related Questions