[LiveComponent] Fix data model radio checkbox#3416
Open
nullodyssey wants to merge 4 commits intosymfony:2.xfrom
Open
[LiveComponent] Fix data model radio checkbox#3416nullodyssey wants to merge 4 commits intosymfony:2.xfrom
nullodyssey wants to merge 4 commits intosymfony:2.xfrom
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.
Bug Fix:
data-modeloverwritesvalueon radio/checkbox Twig ComponentsIssue: When using
data-modelon a child<TwigComponent>that renders a<input type="radio">or<input type="checkbox">, the subscriber was unconditionally writing the parent prop's value into$data['value']. This clobbered the explicitvalue="a"/value="b"option values set by the template author, breaking radio groups, checkbox groups, and boolean checkboxes.Root cause:
DataModelPropsSubscriber::onPreMount()always did$data[$childModel] = $propValue. Fordata-model="selected", the parser resolveschild = 'value', so the prop value blindly overwrote whatevervaluethe template had already set.Fix: Added three-branch logic in the
foreachbody:Radio / checkbox group — when
valuealready exists in$data(template author passed an explicit option value likevalue="b"), preserve it and instead set$data['checked']by comparing the option value against the parent prop. Supports both scalar (radio) and array (multi-checkbox) props.Boolean checkbox — when
type="checkbox"is present in$databut no explicitvaluewas passed, set$data['checked']directly from the boolean prop. Avoids writing a spuriousvalueattribute entirely.All other inputs — unchanged original behavior (
$data[$childModel] = $propValue).Tests added: Three integration tests covering radio group, checkbox group, and boolean checkbox scenarios, verifying that
valueattributes are preserved andcheckedis set correctly.