[LiveComponent] Fix data-model on radio/checkbox inside Twig Components#3680
Open
Amoifr wants to merge 1 commit into
Open
[LiveComponent] Fix data-model on radio/checkbox inside Twig Components#3680Amoifr wants to merge 1 commit into
Amoifr wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Supports the approach discussed in #3412.
data-modelon a Twig Component wrapping<input type="radio">/<input type="checkbox">currently overwrites the per-inputvalueattribute with the current prop value (so every input in a group ends up indistinguishable), anddata-model="selected[]"crashes thePropertyAccessor.DataModelPropsSubscribernow:[]notation (rtrim($parent, '[]')) before resolving the property path.checkedinstead of overwritingvalue. Detection does not rely on atypeprop (which may be hardcoded in the child template, e.g. the ShadcnCheckbox— @Kocal's concern), but on the prop value and the presence of an explicitvalue:boolprop → boolean checkbox → setchecked;value+arrayprop → checkbox group →checked = in_array(value, prop), keepvalue;value+ scalar prop → radio →checked = (value == prop), keepvalue;valueis set from the prop.Comparisons are kept loose to mirror the JS
setValueOnElementbehavior. Tests cover radio, checkbox group (incl. the[]notation), a boolean checkbox whosetypeis hardcoded in the template, and a regular text input (no regression).One edge case worth confirming: a text input carrying both an explicit
valueand adata-modelis now treated as radio/checkbox. This is contradictory usage that is already broken today, so there should be no regression — but happy to adjust if you'd prefer a stricter detection.