In project development, you typically encounter a form of a table, then there may be several elements in the form of the same name, in this case, under the Validate default condition is only to verify the first, and the following elements can not be validated, then there are two ways to solve this problem.
Note: Regardless of the following approach, elements of the same name must have an ID, otherwise there will be no effect.
Method One:
Add the following code to the JS file of the page you want to verify:
/** * Processing for validation of elements with the same name/$ (function () {if ($.validator) {$.validator.prototype.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]"). Not (thi S.settings.ignore). Filter (function () {if!this.name && validator.settings.
Debug && window.console) {console.error ("%o has no name assigned", this); }//Note This line of code//select only the ' the ' the ' only ' for each name, and only those WI
TH rules specified//if (this.name in Rulescache | |!validator.objectlength $ (this). Rules ()) {
return false;
//} Rulescache[this.name] = true;
return true;
}); }
}
});
Method Two: Modify JQuery.validate.js source code
Elements:function () {
var validator = this,
Rulescache = {};
Select all valid inputs inside the form (no submit or Reset buttons) return
$ (this.currentform)
. Find ("input, S Elect, textarea ")
. Not (": Submit,: RESET,: Image, [disabled] ")
. Not (This.settings.ignore)
. Filter ( function () {
if (!this.name && validator.settings.debug && window.console) {
Console.error (" %o has no name assigned ", this);
}
Select only the ' the ' the ' only ' for each name, and only those with the rules specified
//Note if (THIS.name in Rulescache || !validator.objectlength ($ (this). Rules ())} {
//return false; }
Rulescache[this.name] = true;
return true;
};
As you can see from the above code, you just need to comment out the IF statement at the callout.