Content-Length: 315826 | pFad | http://github.com/jquery-validation/jquery-validation/pull/2498/files

F8 Core: Validate inputs with duplicate name / name[] arrays, instead of just the first item by bompus · Pull Request #2498 · jquery-validation/jquery-validation · GitHub
Skip to content

Core: Validate inputs with duplicate name / name[] arrays, instead of just the first item #2498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,22 @@ $.extend( $.validator, {
},

checkForm: function() {
var checkedCache = {};

this.prepareForm();
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
this.check( elements[ i ] );
var element = elements.eq(i);

var type = element.attr( "type" );
if ( type === 'checkbox' || type === 'radio' ) {
// only check the first checkbox/radio input ( https://github.com/jquery-validation/jquery-validation/pull/2431#issuecomment-1172835268 )
if ( element.name in checkedCache ) {
continue;
}
checkedCache[ element.name ] = true;
}
Comment on lines +462 to +469
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear why we check only first checkbox?

What about the cases when we ask user to check boxes which labels does not have a letter?


this.check( element );
}
return this.valid();
},
Expand Down Expand Up @@ -657,8 +670,12 @@ $.extend( $.validator, {
return false;
}

// Select only the first element for each name, and only those with rules specified
if ( name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
if ( name in rulesCache ) {
return true;
}
Comment on lines -660 to +675
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is correct, that we do not allow elements with the same name. I believe this is by RFC. Though I could be wrong, because I did not work with checkbox/radio a lot.


// return only those with rules specified
if ( !validator.objectLength( $( this ).rules() ) ) {
return false;
}

Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/jquery-validation/jquery-validation/pull/2498/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy