开发者

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

开发者 https://www.devze.com 2023-03-11 06:23 出处:网络
So I have a fairly large form with two different sections. Both sections start off as hidden: <fieldset class=\"section1\" style=\"display:none\">

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 w开发者_StackOverflow社区orks 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.


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

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

精彩评论

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