Wednesday, March 16, 2011

jQuery.validate – Setting default ignore rules

Note: This post is from my old blog (2010-03-10)

I’ve been trying to setup jQuery.validate so that it ignores hidden elements on the form. By hidden I mean that the element is not visible; not that it is an input of type hidden.

The definition of defaults.ignore is an array…
ignore: []
… so I pushed my “:hidden” string into the array… but that didn’t work.
This setting is eventually passed to the jQuery .not() function like this:
.not( this.settings.ignore )
So by assigning a string to the defaults like this:
jQuery.validator.defaults.ignore = ":hidden";
The string “:hidden” will be passed to the jQuery .not() function when selecting valid form elements and the elements that are non visible (match the selector “:hidden”) will be ignored during validation…

No comments:

Post a Comment