I want to include a collection type inside another collection type.
It should look like this:
Using just one collection works fine, but I need to edit the prototype of the outer form, so it renders the prototype of the inner form for each line.
Any ideas how could I do that? Also what would be the best way to save
EDIT:
Now I am trying to render the prototype of the nested form:
<ul class="characteristics-container" data-prototype="{{ form_widget(form.characteristics.vars.prototype)|e }}" data-prototype-options="{{ form_widget(form.characteristics.options.vars.prototype|e ) }}">
{# iterate over each existing tag and render its only field: name #}
{% for characteristic in form.characteristics %}
<li>{{ form_row(characteristic.name) }}</li>
<div class="characteristics-options">
{% for opt in form.characteristics.options %}
{% endfor %}
</div>
{% endfor %}
</ul>
It gives error in form_widget(form.characteristics.options.vars.prototype|e
Method "options" for object "SymfonyComponentFormFormView" does not exist in
I tried characteristics[0], and it says the key doesnt exist
Here are my form classes:
PromotionType (the base form)
$builder
->add('characteristics','collection', array(
'label' => 'Caracteristicas',
'type' => new PromotionCharacteristicType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
))
PromotionCharacteristicType
$builder
->add('name',NULL, array('label' => 'Nome'))
->add('options', 'collection', array(
'type' => new PromotionCharacteristicOptionType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
))
;
PromotionCharacteristicOptionType
$builder
->add('name',NULL, array('label' => 'Nome'))
;
The first level prototype, works fine.
See Question&Answers more detail:
os