jquery validate validation plugin resolves multiple identical name only to validate first scenario

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.