Skip to content

[LiveComponent] Fix data model radio checkbox#3416

Open
nullodyssey wants to merge 4 commits intosymfony:2.xfrom
nullodyssey:fix/data-model-radio-checkbox
Open

[LiveComponent] Fix data model radio checkbox#3416
nullodyssey wants to merge 4 commits intosymfony:2.xfrom
nullodyssey:fix/data-model-radio-checkbox

Conversation

@nullodyssey
Copy link
Copy Markdown

Q A
Bug fix? yes
New feature? no
Deprecations? no
Documentation? no
Issues Fix #3412
License MIT

Bug Fix: data-model overwrites value on radio/checkbox Twig Components

Issue: When using data-model on 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 explicit value="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. For data-model="selected", the parser resolves child = 'value', so the prop value blindly overwrote whatever value the template had already set.

Fix: Added three-branch logic in the foreach body:

  1. Radio / checkbox group — when value already exists in $data (template author passed an explicit option value like value="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.

  2. Boolean checkbox — when type="checkbox" is present in $data but no explicit value was passed, set $data['checked'] directly from the boolean prop. Avoids writing a spurious value attribute entirely.

  3. 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 value attributes are preserved and checked is set correctly.

@carsonbot carsonbot added Bug Bug Fix LiveComponent Status: Needs Review Needs to be reviewed labels Mar 28, 2026
@nullodyssey nullodyssey changed the title [LiveComponent] fix: data model radio checkbox [LiveComponent] Fix data model radio checkbox Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiveComponent] data-model on radio and checkbox inside a Twig Component overwrites all value attributes with the current prop value

3 participants