Skip to content

Commit b0b0a4b

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Moving the "On the rendered page" paragraph upwards Rephrasing `data-prototype` paragraph
2 parents 2ad5d8e + e17aaec commit b0b0a4b

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

form/form_collections.rst

+15-17
Original file line numberDiff line numberDiff line change
@@ -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="&lt;div&gt;&lt;label class=&quot; required&quot;&gt;__name__&lt;/label&gt;&lt;div id=&quot;task_tags___name__&quot;&gt;&lt;div&gt;&lt;label for=&quot;task_tags___name___name&quot; class=&quot; required&quot;&gt;Name&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;task_tags___name___name&quot; name=&quot;task[tags][__name__][name]&quot; required=&quot;required&quot; maxlength=&quot;255&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;">
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="&lt;div&gt;&lt;label class=&quot; required&quot;&gt;__name__&lt;/label&gt;&lt;div id=&quot;task_tags___name__&quot;&gt;&lt;div&gt;&lt;label for=&quot;task_tags___name___name&quot; class=&quot; required&quot;&gt;Name&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;task_tags___name___name&quot; name=&quot;task[tags][__name__][name]&quot; required=&quot;required&quot; maxlength=&quot;255&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;">
299-
300303
The goal of this section will be to use JavaScript to read this attribute
301304
and dynamically add new tag forms when the user clicks a "Add a tag" link.
302305
This 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-
389387
To make handling these new tags easier, add an "adder" and a "remover" method
390388
for the tags in the ``Task`` class::
391389

0 commit comments

Comments
 (0)