Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bompus wants to merge2 commits intojquery-validation:master
base:master
Choose a base branch
Loading
frombompus:allow-input-arrays

Conversation

bompus
Copy link

Description

Replaces#2000 and#2431 with simpler logic, and I believe that .elements() should return all of the eligible elements.

Previously, if you had 2+ inputs using name arrays, such as:

<inputtype="text"name="todo_item[]"data-rule-required="true"/><inputtype="text"name="todo_item[]"data-rule-required="true"/><inputtype="text"name="todo_item[]"data-rule-required="true"/>

It would only hit validation on the first input in the array, allowing all the remaining inputs with the same name to remain empty.

Technically, I'm pretty sure the following, without using [] syntax would have the same problem:

<inputtype="text"name="first_name"data-rule-required="true"/><inputtype="text"name="first_name"data-rule-required="true"/><inputtype="text"name="first_name"data-rule-required="true"/>

I'm not familiar with the testing framework, but please review the idea behind this PR first, and if you're confident that it will be merged if tests are included, I'll dig deeper into testing.

Comment on lines +462 to +469
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;
}

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 havea letter?

Comment on lines -660 to +675
// 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;
}

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.

@KES777
Copy link

KES777 commentedJan 26, 2025
edited
Loading

@bytestream I am not familiar with checkbox/radio input types, but it looks like they try to resolve a different problem.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@KES777KES777KES777 left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@bompus@KES777@bytestream

[8]ページ先頭

©2009-2025 Movatter.jp