Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Form: choice with expanded=true does not retain boolean values #15573

Copy link
Copy link
Closed
@imphil

Description

@imphil
Issue body actions

I have a form with the following code:

$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
  'multiple' => false,
  'expanded' => false,
  'choices' => array(
      'label a' => false,
      'label b' => true,
  ),
  'choices_as_values' => true,
));

When submitting the form, none of the two radio buttons are selected, i.e. the values are lost.

I've written a unit test for it in imphil@71a59b7

Currently it fails with

There were 2 failures:

1) Symfony\Component\Form\Tests\Extension\Core\Type\ChoiceTypeTest::testSubmitSingleExpandedBooleanValueFalse
Failed asserting that false is identical to '0'.

/home/philipp/src/symfony/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php:354

2) Symfony\Component\Form\Tests\Extension\Core\Type\ChoiceTypeTest::testSubmitSingleExpandedBooleanValueTrue
Failed asserting that true is identical to '1'.

/home/philipp/src/symfony/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php:373

The problem only happens with boolean values and expanded=true. It seems that a proper conversion to the view data is missing. Unfortunately I have no idea about the inner workings of Symfony -- maybe someone with a bit more experience can have a look?

(This seems to be similar to #14877, but maybe not exactly the same, so I didn't want to hijack that issue.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.