I'm building a form with Symfony2 and need to group some checkboxes. I simply cannot figure out how to pass choices/label along to the checkboxes in BonusGroup.
Form:
$builder->add('groups', 'collection', array(
     'type' => new BonusGroup(),
     'allow_add' => false,
     'allow_delete' => false,
     'by_reference' => false
));
BonusGroup():
$builder->add('bonus', 'choice', array(
      'choices'  => $options['bonus'],
      'multiple' => true,
      'expanded' => true
));
View.twig:
{% for group in form.groups %}
     {{ form_label(group) }}
     {% for final in group.bonus %}
          {{ form_widget(final) }}
     {% endfor %}
{% endfor %}
Passing data to form:
$data = array(
    'groups' =>
        array ('Group 1 label' => array())
);
$form = $app['form.factory']->createBuilder(new Form(), $data))->getForm();
Any tips?
Thanks!
First, change form_widget to form_row, but it won't work yet because collection type need a piece of JavaScript to work.
See examples here: http://symfony.com/doc/2.1/reference/forms/types/collection.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With