File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -400,9 +400,12 @@ one example:
400
400
// Get the data-prototype explained earlier
401
401
var prototype = collectionHolder .attr (' data-prototype' );
402
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
+
403
406
// 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 );
406
409
407
410
// Display the form in the page in an li, before the "Add a tag" link li
408
411
var $newFormLi = $ (' <li></li>' ).append (newForm);
You can’t perform that action at this time.
0 commit comments