File tree 1 file changed +4
-4
lines changed
Filter options
1 file changed +4
-4
lines changed
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ the following ``data-prototype`` attribute to the existing ``<ul>`` in your temp
243
243
244
244
.. code-block :: html+twig
245
245
246
- <ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e('html_attr') }}"></ul>
246
+ <ul class="tags" data-index="{{ form.tags|length > 0 ? form.tags|last.vars.name + 1 : 0 }}" data- prototype="{{ form_widget(form.tags.vars.prototype)|e('html_attr') }}"></ul>
247
247
248
248
Now add a button just next to the ``<ul> `` to dynamically add a new tag:
249
249
@@ -255,7 +255,7 @@ On the rendered page, the result will look something like this:
255
255
256
256
.. code-block :: html
257
257
258
- <ul class =" tags" data-index =" {{ form.tags|length > 0 ? form.tags|last.vars.name + 1 : 0 }} " 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> ; " >
258
+ <ul class =" tags" data-index =" 0 " 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> ; " >
259
259
260
260
.. seealso ::
261
261
@@ -537,7 +537,7 @@ First, add a "delete this tag" link to each tag form:
537
537
})
538
538
539
539
// ... the rest of the block from above
540
-
540
+
541
541
function addFormToCollection () {
542
542
// ...
543
543
@@ -553,7 +553,7 @@ The ``addTagFormDeleteLink()`` function will look something like this:
553
553
const removeFormButton = document .createElement (' button' )
554
554
removeFormButton .classList
555
555
removeFormButton .innerText = ' Delete this tag'
556
-
556
+
557
557
tagFormLi .append (removeFormButton);
558
558
559
559
removeFormButton .addEventListener (' click' , (e ) => {
You can’t perform that action at this time.
0 commit comments