Reputation: 913
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.
Upvotes: 0
Views: 2350
Reputation: 913
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.
Upvotes: 1
Reputation: 8855
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.
Upvotes: 0