I have 3 nested form in Symfony2. I won't get into all the code here beacuse it can be long. I'm just gonna show an example of what I want to do here.
So, let's say that
Category
Product
Tag
AbstractType
allow_add
allow_delete
by_reference
$builder->add('product', 'collection', array(
'type' => new ProductType(),
'prototype' => true,
'prototype_name' => '__product__'
));
$builder->add('tag', 'collection', array(
'type' => TagType(),
'prototype' => true,
'prototype_name' => '__tag_name__'
));
divs
<div class="ResourceAttributePrototype" data-product-prototype="{{ form_widget(form.product.vars.prototype)|e }}"></div>
<div class="Prototype" data-tag-prototype="{{ form_widget(form.product.vars.prototype.children['tag'].vars.prototype)|e }}"></div>
If you simply render out the children first, this problem goes away.
Example from one of my projects:
Render these prototypes first:
campaignForm.campaignRows.vars.prototype.children['campaignTexts'].vars.prototype campaignForm.campaignRows.vars.prototype.children['featuredItems'].vars.prototype campaignForm.campaignRows.vars.prototype.children['campaignImageCampaigns'].vars.prototype
Then the parent:
campaignForm.campaignRows.vars.prototype
Works for me, hopefully it works for you too. I assume the children are set as rendered internally somehow which causes the problem you have.