Skip to content

Fix: Omit hidden input before checkbox group#314

Open
ftes wants to merge 3 commits into
germsvel:mainfrom
ftes:fix/hidden-checkbox-group-input-order
Open

Fix: Omit hidden input before checkbox group#314
ftes wants to merge 3 commits into
germsvel:mainfrom
ftes:fix/hidden-checkbox-group-input-order

Conversation

@ftes
Copy link
Copy Markdown
Contributor

@ftes ftes commented Apr 29, 2026

Omit hidden 'reset' input that appears before checkbox group if any checkboxes are checked.

What changed?

  • Better preserve DOM order of form elements better when building form data.

Why make these changes?

A hidden input before a checkbox group can be used to reset the value if all checkboxes are unchecked.
However, if checkboxes are checked, then the hidden input should be effectively ignored.
Plug/Phoenix can handle this if the field values arrive in DOM order.

In forms like:

<input type="hidden" name="list" value="" />
<input type="checkbox" name="list[]" value="one" />
<input type="checkbox" name="list[]" value="two" />

PhoenixTest previously collected controls by selector category and stored FormData in a map. That lost DOM order and collapsed repeated field names, which could cause the hidden scalar entry to interfere with the checkbox array payload.

This PR is only a partial improvement. The ideal solution would be to submit form data in the exact DOM order a browser would, end to end.

@ftes ftes force-pushed the fix/hidden-checkbox-group-input-order branch from 22300cc to 462f68f Compare April 29, 2026 05:07
Comment thread lib/phoenix_test/element/form.ex Outdated
nil ->
data ++ new_entries

first_index ->
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a bit of a crux to handle multiple fields with same name.

@ftes ftes marked this pull request as ready for review April 29, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant