Grouping checkboxes in Symfony2

symfony, symfony-forms

Solution

Ok so here's the form_theme solution for this

{% block _user_code_widget %}
    <div {{ block('widget_container_attributes') }}>
        {% for name, choices in form.vars.choices %}
            <ul>
                <li class="checkbox_category">
                    <input type="checkbox" class="checkallsub" /> {{ name }}
                </li>

                {% for key,choice in choices %}
                    <li class="indent">
                        {{ form_widget(form[key]) }}
                        {{ form_label(form[key]) }}
                    </li>
                {% endfor %}
            </ul>
        {% endfor %}
    </div>
{% endblock %}

Of course the extra js layer is missing, but you get the idea.

Problem

It seems that Symfony2 Form component does not handle this common case. Below is what I want in my html The code looks like : ``` ->add('code', 'choice', array( 'choices' => array( 'Food' => array('pizza', 'burger', 'icecream'), 'Music' => array('poney', 'little', 'pocket'), ), 'multiple' => true, 'expanded' => true, 'required' => true )); ``` Which gives in reality the wrong output : It's wierd because the case with `expanded => false` is correctly handled How to handle that case please ?

Original source