Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ you need is this JavaScript code:
// add-collection-widget.js
jQuery(document).ready(function () {
jQuery('.add-another-collection-widget').click(function (e) {
var list = jQuery(jQuery(this).attr('data-list'));
var list = jQuery(jQuery(this).attr('data-list-selector'));
// Try to find the counter of the list or use the length of the list
var counter = list.data('widget-counter') || list.children().length;

Expand Down Expand Up @@ -176,7 +176,8 @@ And update the template as follows:
{# store the prototype on the data-prototype attribute #}
<ul id="email-fields-list"
data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}"
data-widget-tags="{{ '<li></li>'|e }}">
data-widget-tags="{{ '<li></li>'|e }}"
data-widget-counter="{{ form.emails|length }}">
{% for emailField in form.emails %}
<li>
{{ form_errors(emailField) }}
Expand All @@ -187,7 +188,7 @@ And update the template as follows:

<button type="button"
class="add-another-collection-widget"
data-list="#email-fields-list">Add another email</button>
data-list-selector="#email-fields-list">Add another email</button>

{# ... #}
{{ form_end(form) }}
Expand Down