Jquery validator and fields that were hidden

I am trying to get a jquery validationn plugin not to check for hidden fields when submitting. For example, if we have HTML:

<div id="1"> <input type="text" class="digits"> </div> <div id="2"> <input type="text" class="digits"> </div> 

And then call:

 $('div#2').hide(); 

and submit the form, even if the second input may contain incorrect data entered into the form that must be submitted. I wanted to change the verification code, but could not find the corresponding fragments.

0
javascript jquery jquery-validate
source share
1 answer

The easiest way to remove validation from fields is to add the disabled attribute to them.

 var $div2 = $('div#2'); $div2.hide(); $('input, select, textarea', $div2).attr('disabled', 'disabled'); 

And they will not be verified. But this also leads to the fact that disabled fields should not be sent to the server. If you do not need these manually hidden fields to send to the server, the technique is good.

And another way is to manually add and remove all validation rules from an element using delete rules and add rules . This, of course, is more complicated, since you have to add and delete each rule, one for each input.

+3
source share

All Articles