Scenario One: If the project is not just an individual page with multiple name validations,
Then use prototype to write, add this code in the JS initialization of the page you want to use multiple name
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 (This.settings.ignore)
. filter (function () {
if (!this.name && validator.settings.debug && window.console) {
Console.error ("%o have No Name assigned", this);
}
Note This line of code
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;
});
}
}
Scenario Two: Modify the source file so that all pages can verify multiple name
Find the source code (not compressed min.js) using ctrl+f find THIS.name in Rulescache. Take this line if you can judge the comment.
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 (This.settings.ignore)
. filter (function () {
if (!this.name && validator.settings.debug && window.console) {
Console.error ("%o have 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;
});
},
If it is compressed JS min.js:
Find this paragraph (c[this.name]=!0,!0)}) and change it to
return!this.name && b.settings.debug && window.console && console.error ("%o has no name assigned ", this),
THIS.name in C | | !b.objectlength (A (this). Rules ())?! 1: (C[this.name] =! 0,!0) Hide this paragraph
Then add the following line of code to
C[this.name] =! 0,!0
The above is the online solution, prepared here, so that later.
jquery validate validation plugin resolves multiple identical name only to validate first scenario