-
Notifications
You must be signed in to change notification settings - Fork 132
Fix checkbox ID generation to preserve brackets in field names #3878
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
530ee71
Initial plan
Copilot 2230900
Fix checkbox ID generation to preserve brackets in names
Copilot 0c105cd
Fix ID generation logic to handle boolean vs array schemes correctly
Copilot f694237
Simplify conditional check for trailing brackets
Copilot 357194c
Address code review feedback: remove trailing whitespace and clarify …
Copilot 90914ef
Fix generated field ids to remove brackets
jonrohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/view-components": patch | ||
| --- | ||
|
|
||
| Fix generated field ids to remove brackets | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,4 +61,40 @@ def test_nested_form_can_be_hidden_independently | |
| assert_selector "input[name=foo]" | ||
| assert_selector "input[name=bar]", visible: :hidden | ||
| end | ||
|
|
||
| def test_preserves_brackets_in_generated_ids | ||
| render_in_view_context do | ||
| primer_form_with(url: "/foo") do |f| | ||
| render_inline_form(f) do |check_form| | ||
| check_form.check_box( | ||
| name: "permissions[3]", | ||
| label: "Foo", | ||
| value: "bar", | ||
| scheme: :array | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # The ID should preserve brackets from the name | ||
| assert_selector "input[id='permissions[3]_bar']" | ||
| assert_selector "label[for='permissions[3]_bar']" | ||
| end | ||
|
|
||
| def test_preserves_brackets_in_generated_ids_with_boolean_scheme | ||
| render_in_view_context do | ||
| primer_form_with(url: "/foo") do |f| | ||
| render_inline_form(f) do |check_form| | ||
| check_form.check_box( | ||
| name: "user[settings][email]", | ||
| label: "Email notifications" | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # For boolean scheme, the ID should just be the name with brackets preserved | ||
| assert_selector "input[id='user[settings][email]']" | ||
| assert_selector "label[for='user[settings][email]']" | ||
| end | ||
|
Comment on lines
+84
to
+99
|
||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changeset description says "Fix generated field ids to remove brackets" but this is incorrect. The fix actually preserves brackets in generated field IDs, not removes them. The PR description and implementation both confirm that brackets are being preserved (e.g.,
permissions[3]_fooinstead ofpermissions_3_foo).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀