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

Handle array-like objects when working with checkboxes #1155

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

Lustmored
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
Tickets
License MIT

First of all please take a look at added test cases. I think it shows the purpose of this change clearly.

Background:
Recently when working with forms inside a component I ran into a corner case, where Symfony forms are setting a non-zero-indexed array for the properties of ChoiceType with both multiple and expanded. It breaks live-component model assumption that multiple checkboxes keep their value as an array, which in JavaScript is always zero-indexed.

It happens after a pretty weird set of steps:

  • check any option (foo)
  • check any other option (bar)
  • check the third option (baz)
  • uncheck option 'foo' <- Symfony forms store current value as [1 => 'bar', 2 => 'baz']
  • uncheck option 'bar' <- at this point current implementation is treating checkboxes as a single value and send back null instead of ['baz'].

This simple change fixes this flow (tested on a real life project). I don't see any correlation with failing tests.

@weaverryan
Copy link
Member

Very-well explained and excellent tests - THANK YOU. Check boxes are deceivingly complex

@weaverryan weaverryan merged commit d341f7b into symfony:2.x Oct 2, 2023
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.

2 participants