Question

I'm displaying a choice field in Symfony 2.0.4 with multiple checkboxes. Symfony always displays the first checkbox as checked and I would like to disable this behavior. I've tried setting the underlying entity's field to an empty array before building the form but this didn't have any effect. Is this a glitch in the Symfony version or is there a special way of achieving this?

EDIT:
By choice field with multiple checkboxes I mean a choice field having the expanded and multiple options set to true.

Was it helpful?

Solution

It seems that this was my stupid mistake. I was overriding the form theme and in the choice_widget_expanded block I was adding the checked flag for the first element of the choice array.

OTHER TIPS

You need to add in your form class :

$builder->add('yourField', 'choice', array(
    'choices'     => $choices
    'required'    => false,
    ....
));

You can find more information in the ChoiceField type documentation http://symfony.com/doc/2.0/reference/forms/types/choice.html

Also check that you don't have any JavaScript which is checking the first value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top