Skip to content

ChoiceType returns wrong data on submit if clearMissing is false #16802

Closed
@ossinkine

Description

@ossinkine

I've created TestFormType

class TestType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('text', 'text')
            ->add('choice', 'choice', ['choices' => ['FOO' => 'foo', 'BAR' => 'bar'], 'expanded' => true])
        ;
    }

    public function getName()
    {
        return 'test';
    }
}

created the form and trying to submit data

$data = [
    'text'   => 'foo',
    'choice' => 'foo',
];
$form = $this->createForm('test', $data);
$form->submit(
    [
        'text'   => 'bar',
        'choice' => 'bar',
    ],
    false
);

and now $form->getData() will return an array:

array (size=2)
    'text' => string 'bar' (length=3)
    'choice' => string 'foo' (length=3)

I expect to receive bar for both fields.

I'm working on the latest version of 4.4 branch
See the reproducer for this issue https://github.com/ossinkine/symfony-issue-16802

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