@@ -262,16 +262,25 @@ add the ``allow_add`` option to your collection field::
262262 ]);
263263 }
264264
265- In addition to telling the field to accept any number of submitted objects, the
266- `` allow_add `` also makes a * "prototype" * variable available to you. This "prototype"
267- is a little "template" that contains all the HTML to be able to render any
268- new "tag" forms. To render it, make the following change to your template:
265+ The `` allow_add `` option also makes a `` prototype `` variable available to you.
266+ This "prototype" is a little "template" that contains all the HTML needed to
267+ dynamically create any new "tag" forms with JavaScript. To render the prototype, add
268+ the following `` data-prototype `` attribute to the existing `` <ul> `` in your template:
269269
270270.. code-block :: html+twig
271271
272272 <ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e('html_attr') }}">
273- ...
274- </ul>
273+
274+ On the rendered page, the result will look something like this:
275+
276+ .. code-block :: html
277+
278+ <ul class =" tags" data-prototype =" < ; div> ;< ; label class=" ; required" ;> ; __name__< ; /label> ;< ; div id=" ; task_tags___name__" ;> ;< ; div> ;< ; label for=" ; task_tags___name___name" ; class=" ; required" ;> ; Name< ; /label> ;< ; input type=" ; text" ; id=" ; task_tags___name___name" ; name=" ; task[tags][__name__][name]" ; required=" ; required" ; maxlength=" ; 255" ; /> ;< ; /div> ;< ; /div> ;< ; /div> ; " >
279+
280+ .. seealso ::
281+
282+ If you want to customize the HTML code in the prototype, see
283+ :ref: `form-custom-prototype `.
275284
276285.. note ::
277286
@@ -291,12 +300,6 @@ new "tag" forms. To render it, make the following change to your template:
291300
292301 {{ form_widget(form.tags.vars.prototype.name)|e }}
293302
294- On the rendered page, the result will look something like this:
295-
296- .. code-block :: html
297-
298- <ul class =" tags" data-prototype =" < ; div> ;< ; label class=" ; required" ;> ; __name__< ; /label> ;< ; div id=" ; task_tags___name__" ;> ;< ; div> ;< ; label for=" ; task_tags___name___name" ; class=" ; required" ;> ; Name< ; /label> ;< ; input type=" ; text" ; id=" ; task_tags___name___name" ; name=" ; task[tags][__name__][name]" ; required=" ; required" ; maxlength=" ; 255" ; /> ;< ; /div> ;< ; /div> ;< ; /div> ; " >
299-
300303 The goal of this section will be to use JavaScript to read this attribute
301304and dynamically add new tag forms when the user clicks a "Add a tag" link.
302305This example uses jQuery and assumes you have it included somewhere on your page.
@@ -381,11 +384,6 @@ into new ``Tag`` objects and added to the ``tags`` property of the ``Task`` obje
381384
382385 You can find a working example in this `JSFiddle `_.
383386
384- .. seealso ::
385-
386- If you want to customize the HTML code in the prototype, read
387- :ref: `form-custom-prototype `.
388-
389387To make handling these new tags easier, add an "adder" and a "remover" method
390388for the tags in the ``Task `` class::
391389
0 commit comments