jquery-validation: don't validate hidden fields

Hi, i change the function:

elements: function() {
            var validator = this,
                rulesCache = {};

            // select all valid inputs inside the form (no submit or reset buttons)
            return $(this.currentForm)
            .find("input, select, textarea")
            .not(":submit, :reset, :image, [disabled]")

to:

            .not(":submit, :reset, :image, [disabled], :hidden")

to not validate hidden fields… (in my case, sometimes a field will be hidden in the submit).

is this a valid change to the project?

About this issue

  • Original URL
  • State: open
  • Created 13 years ago
  • Comments: 24 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@steveharrison we cannot change the selector to affect more elements as it does atm with breaking BC. We can discuss this for a possible 2.x version, but this will not be something happening in the near future

If I make a field required, I expect that because of this it will be validated. The visibility of that field should not come into question at all.

This change breaks a TON of code… anything in a collapsed accordion, anything in a tab that is not in focus. If I’ve taken the time to annotate a field to be validated, it should be validated.

I just spent two hours trying to figure out why was my field ignored.

<input type="hidden" class="required">

I’ve put class=“required” in it, why no validation? Then I thought okay, maybe they don’t validate hiddens… so I did:

<input type="text" class="required hidden">

And still no validation.

I thought to myself: “why not validate those fields? if you don’t want something validated, you simply don’t put class=“required” there…”

At that point I was breathing fire and went to the sourcecode, then to changelog and here.

Looking at #263, this looks like a rather ugly hack than a solution to the original problem.

How about making “:hidden” the default for the ignore option? That way it can be overriden, but doesn’t have to be set all the time.