I am using the "jQuery validation plug-in 1.7".
The problem is why multiple $ (: input) elements that have the same name are not checked
- $ .validator.element method:
elements: function() { var validator = this, rulesCache = {}; // select all valid inputs inside the form (no submit or reset buttons) // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved return $([]).add(this.currentForm.elements) .filter(":input") .not(":submit, :reset, :image, [disabled]") .not( this.settings.ignore ) .filter(function() { !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this); // select only the first element for each name, and only those with rules specified if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) return false; rulesCache[this.name] = true; return true; }); },
Condition
if (this.name in rulesCache || .....
estimates that the second and next elements have the same name true ....
The solution will have the condition:
(this.id || this.name) in rulesCache
Sorry, JS puritans, that (this.id || this.name) is not 100% ...
Sure,
rulesCache [this.name] = true;
Line
must also be amended accordingly.
So the $ .validator.prototype.elements method will be:
$(function () { if ($.validator) { //fix: when several input elements shares the same name, but has different id-ies.... $.validator.prototype.elements = function () { var validator = this, rulesCache = {}; // select all valid inputs inside the form (no submit or reset buttons) // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved return $([]).add(this.currentForm.elements) .filter(":input") .not(":submit, :reset, :image, [disabled]") .not(this.settings.ignore) .filter(function () { var elementIdentification = this.id || this.name; !elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this); // select only the first element for each name, and only those with rules specified if (elementIdentification in rulesCache || !validator.objectLength($(this).rules())) return false; rulesCache[elementIdentification] = true; return true; }); }; }
});
Motlicek Petr Jun 28 '11 at 19:29 2011-06-28 19:29
source share