Skip to content

ChoiceType: 0.0 floats as choice does not get initial selected #20443

@hvanoch

Description

@hvanoch

I have a form with a ChoiceType like this:

       $builder
            ->add('vatRate', ChoiceType::class, [
                'expanded' => true,
                'choices' => [
                    '0%' => 0.0,
                    '6%' => 0.06,
                    '21%' => 0.21,
                ],
                'choices_as_values' => true
            ]);

My object passed to the form has 0.0 (float) as initial value, but the first item of the radio buttons does not get selected/checked. I tried several configurations but nothing seems to work.
Is this a bug with the formbuilder not being able to handle floats correctly?

I am on symfony 2.8.13

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