This post focuses on the use of pre-existing conventions in the branch template.
Based on the “How to Insert a Collection of Forms” from the Symfony Cookbook ( http://symfony.com/doc/master/cookbook/form/form_collections.html ), you can simply enter any form of html_escaped data that you want to use in the prototype data (it can be considered a hack, but it works great), and only pages using this template will change.
In this example, they tell you:
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}"> ... </ul>
This can be successfully replaced with something like:
<table class="tags" data-prototype="<tr> <td><div><input type="text" id="task_tags__name__tagId" name="task[tags][__name__][taskId]" disabled="disabled" required="required" size="10" value="" /></div></td> <td><div><input type="text" id="task_tags__name__tagName" name="task[tags[__name__][tagName]" required="required" value="" /></div></td></tr>"> <tr> <th>Id</th> <th>Name</th> </tr> <tr> ...pre existing data here... </tr> </table>
If the attribute of the data type of the table with the above class tags is a version with html-escaping (and the rows deleted are deleted, although spaces are in order and required):
<tr> <td><div><input type="text" id="task_tags__name__tagId" name="task[tags][__name__][taskId]" disabled="disabled" required="required" size="10" value="" /></div></td> <td><div><input type="text" id="task_tags__name__tagName" name="task[tags[__name__][tagName]" required="required" value="" /></div></td> </tr>
... but you must also configure javascript in the example to add tr instead of li elements:
function addTagForm(collectionHolder, $newLinkTr) { ...
For me, the next step is to figure out how to define a prototype in an external file, which I can somehow call in the branch template for a data prototype that dynamically works with the form. Something like:
<table class="tags" data-prototype="{{somefunction('App\Bundle\Views\Entity\TagsPrototypeInTable')}}">
So, if one of the other posts describes this, and I'm too tight, or if someone knows how to do this, say so!
There is a link to something from Francois gitHub, but I have not seen any explanation, so I think this is probably the more dynamic method that I will receive in one of these coming days.
World Steve
Update:
You can also use only parts of the prototype:
data-prototype="<tr> <td>{{ form_row(form.tags.vars.prototype.tagId) | e }}</td> <td>{{ form_row(form.tags.vars.prototype.tagName) | e }}</td></tr>"
If the attribute of the data type of the table with the above class tags is a version with html-escaping (and the rows deleted are deleted, although spaces are in order and required):
<td>{{ form_row(form.tags.vars.prototype.tagId) | e }}</td> <td>{{ form_row(form.tags.vars.prototype.tagName) | e }}</td>
(I used http://www.htmlescape.net/htmlescape_tool.html .)
Symfony will replace the information between the {{}} html_escaped window (due to the "| e" field) when the page is displayed. Thus, any setting at the field level is not lost, but! you must manually add and remove fields in the prototype, as you do with an entity :)