Skip to content Skip to sidebar Skip to footer

Jquery Validator And Fields That Have Been Hidden

I'm trying to get the Jquery validationn plugin to not validate hidden fields on submission. For example, if we have HTML like this:

Solution 1:

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

var $div2 = $('div#2');
$div2.hide();

$('input, select, textarea', $div2).attr('disabled', 'disabled');

And they will not be validated. But this also causes disabled fields not to be submitted on server. If you do not need these manually hidden fields to be submitted on server, technique is good.

And another way is to manually add and remove all of the validation rules from the element, using remove rules and add rules functions. This is of course more complicated, as you will have to add and remove each rule one by one for each input.


Post a Comment for "Jquery Validator And Fields That Have Been Hidden"