Skip to content

Commit d6b1745

Browse files
khepinweaverryan
authored andcommitted
dynamic form collection: put all elements for javascripts in js rather than initial html
1 parent 2c8a547 commit d6b1745

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

cookbook/form/form_collections.rst

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,31 +309,7 @@ as it allows for more simple cross-browser manipulation of the page.
309309
First let's add a link on the ``new`` form with a class ``add_tag_link``.
310310
Everytime this is clicked by the user, we will add an empty tag for him::
311311

312-
{% extends "::base.html.twig" %}
313-
{% block body %}
314-
<h1>Product creation</h1>
315-
316-
<form action="{{ path('product_create') }}" method="post" {{ form_enctype(form) }}>
317-
{{ form_widget(form) }}
318-
<p>
319-
<button type="submit">Create</button>
320-
</p>
321-
</form>
322-
323-
<ul class="record_actions">
324-
<li>
325-
<a href="{{ path('product') }}">
326-
Back to the list
327-
</a>
328-
</li>
329-
<li>
330-
<a href="#" class="add_tag_link">
331-
Add a tag
332-
</a>
333-
</li>
334-
</ul>
335-
{% include "AcmeTodoBundle:Todo:js.html.twig" %}
336-
{% endblock %}
312+
$('.record_action').append('<li><a href="#" class="add_tag_link">Add a tag</a></li>');
337313

338314
We also include a template containing the javascript needed to add
339315
the form elements when the link is clicked.
@@ -357,7 +333,9 @@ Our script can be as simple as this::
357333
// Display the form in the page
358334
collectionHolder.append(form);
359335
}
360-
336+
// Add the link to add tags
337+
$('.record_action').append('<li><a href="#" class="add_tag_link">Add a tag</a></li>');
338+
// When the link is clicked we add the field to input another tag
361339
$('a.jslink').click(function(event){
362340
addTagForm();
363341
});

0 commit comments

Comments
 (0)