0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

AFAIK empty_value and empty_data do not work for choice types with expanded => true and multiple => true, i.e. a checkbox array. At least that's what the documentation says.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.