Skip to content

Commit ec46d85

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: cookbook/form/form_collections.rst
2 parents 6c9dc44 + 3ab0a5c commit ec46d85

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cookbook/form/form_collections.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,12 @@ one example:
400400
// Get the data-prototype explained earlier
401401
var prototype = collectionHolder.attr('data-prototype');
402402
403+
// count the current form inputs we have (e.g. 2), use that as the new index (e.g. 2)
404+
var newIndex = collectionHolder.find(':input').length;
405+
403406
// Replace '__name__' in the prototype's HTML to
404-
// instead be a number based on the current collection's length.
405-
var newForm = prototype.replace(/__name__/g, collectionHolder.children().length - 1);
407+
// instead be a number based on how many items we have
408+
var newForm = prototype.replace(/__name__/g, newIndex);
406409
407410
// Display the form in the page in an li, before the "Add a tag" link li
408411
var $newFormLi = $('<li></li>').append(newForm);

0 commit comments

Comments
 (0)