8000 Choice type expanded with boolean choices with choices_as_values always preselects `false` value · Issue #17718 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Choice type expanded with boolean choices with choices_as_values always preselects false value #17718
Closed
@webdevilopers

Description

@webdevilopers

I've updated to 2.7 and changed my choice types to use choices_as_values.
Most of my choices are simple "No" or "Yes". But they must not be preselected - the user is forced to choose. That is why none of my radio buttons is initially checked.

I tried this with 2.7:

$builder->add('aberdeenBlind', 'choice', array(
                'choices' => array(
                    'Ja' => true,
                    'Nein' => false
                ),
                'choices_as_values' => true,
                'expanded' => true,
                'required' => true
            ))

Unfortunately the second radio button (false => 'Nein') is preselected. This also happens when flipping the order of the choices. The false choice is always preselected.

I played around with other options e.g. placeholder, empty_* etc. but then I recognized:
This only seems to happen when using boolean values. The following example would not preselect any value:

$builder->add('aberdeenBlind', 'choice', array(
                'choices' => array(
                    'Ja' => 'Y', // or '1'
                    'Nein' => 'N' // or '0'
                ),
                'choices_as_values' => true,
                'expanded' => true,
                'required' => true
            ))

Possibly related:

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

      0