Skip to content
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