We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
2 parents6c9dc44 +3ab0a5c commitec46d85Copy full SHA for ec46d85
cookbook/form/form_collections.rst
@@ -400,9 +400,12 @@ one example:
400
// Get the data-prototype explained earlier
401
var prototype=collectionHolder.attr('data-prototype');
402
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
+
406
// Replace '__name__' in the prototype's HTML to
-// instead be a number based onthe current collection's length.
-var newForm=prototype.replace(/__name__/g,collectionHolder.children().length-1);
407
+// instead be a number based onhow many items we have
408
+var newForm=prototype.replace(/__name__/g,newIndex);
409
410
// Display the form in the page in an li, before the "Add a tag" link li
411
var $newFormLi=$('<li></li>').append(newForm);