Skip to content

[Form] Conflict between empty Placeholder value and false value in ChoiceType #17677

@raziel057

Description

@raziel057

Using Symfony 2.8.2 or 3.0.2.
You can reproduce the problem with this simple statement:

$builder->add('participation', ChoiceType::class, array(
     'choices' => [ 'yes' => true, 'no' => false ],
    'placeholder' => 'Select a value',
    'empty_data' => null,
    'choices_as_values' => true,
));

Expected result:

<select name="filter[participation]" id="filter_participation">
    <option value="">Select a value</option>
    <option value="1">Yes</option>
    <option selected="selected" value="0">No</option>
</select>

Actual result:

<select name="filter[participation]" id="filter_participation">
    <option value="1">Yes</option>
    <option selected="selected" value="">No</option>
</select>

Dump of choiceList:

boolean_choice_dump

As you can see, the placeholder is not rendered. If I add a new empty value in 'choices', I got an empty value in the view plus the placeholder value.

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