I've got a problem with displaying collection in my form.
When displaying my entity collection I've got something like this :
0 Name: myInputName Address: myInputAddress 1 Name: myInputName Address: myInputAddress
My question is why Symfony2 display the index...
And this for all saved entities into my collection...
Here the code I use:
$builder ->add('person', 'collection', array( 'label' => ' ', 'type' => new PersonType(), 'prototype' => true, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, )) ;
In my twig file:
<div> {{ form_widget(edit_form) }} </div>
Help please
Sam
Removing indexes (labels) for collection items:
$builder ->add('person', 'collection', array( ... 'options' => array('label' => false) )) ;
Use key
entry_options
instead ofoptions
for Symfony 3 and 4
If you want to add custom labels per row you can produce the form yourself:
{{ form_start(edit_form) }} {% for person in form.persons %} {{ form_row(person, {'label': 'custom label per item' }) }} {% endfor %} {{ form_end(edit_form) }}
Note: tested on Symfony 2.3 & 2.4
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