Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] ChoiceType children are always considered valid #60690

Open
@ker0x

Description

@ker0x

Symfony version(s) affected

6.4.* / 7.*

Description

When a ChoiceType field with 'expanded' => true is submitted, all children are considered valid even if a selected value is invalid. Only the parent is considered invalid ('valid' => false in the form view data).

How to reproduce

Create a form with the following field:

->add('choice_checkbox', ChoiceType::class, [
    'choices' => [
        'Foo' => 'foo',
        'Bar' => 'bar',
        'Baz' => 'baz',
    ],
    'expanded' => true,
    'multiple' => true,
    'constraints' => new Assert\EqualTo('baz'),
])

Then select foo and/or bar and submit the form.

  • Parent field is invalid ('valid' => false)
  • Children are valid ('valid' => true) whereas foo and bar should be invalid ('valid' => false)

Image

reproducer

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions