@@ -280,6 +280,17 @@ new "tag" forms. To render it, make the following change to your template:
280
280
...
281
281
</ul>
282
282
283
+ On the rendered page, the result will look something like this:
284
+
285
+ .. code-block :: html
286
+
287
+ <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> ; " >
288
+
289
+ .. seealso ::
290
+
291
+ If you want to customize the HTML code in the prototype, see
292
+ :ref: `form-custom-prototype `.
293
+
283
294
.. note ::
284
295
285
296
If you render your whole "tags" sub-form at once (e.g. ``form_row(form.tags) ``),
@@ -298,12 +309,6 @@ new "tag" forms. To render it, make the following change to your template:
298
309
299
310
{{ form_widget(form.tags.vars.prototype.name)|e }}
300
311
301
- On the rendered page, the result will look something like this:
302
-
303
- .. code-block :: html
304
-
305
- <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> ; " >
306
-
307
312
The goal of this section will be to use JavaScript to read this attribute
308
313
and dynamically add new tag forms when the user clicks a "Add a tag" link.
309
314
To make things simple, this example uses jQuery and assumes you have it included
@@ -389,11 +394,6 @@ into new ``Tag`` objects and added to the ``tags`` property of the ``Task`` obje
389
394
390
395
You can find a working example in this `JSFiddle `_.
391
396
392
- .. seealso ::
393
-
394
- If you want to customize the HTML code in the prototype, read
395
- :ref: `form-custom-prototype `.
396
-
397
397
To make handling these new tags easier, add an "adder" and a "remover" method
398
398
for the tags in the ``Task `` class::
399
399
0 commit comments