|
@@ -337,9 +337,17 @@ var Admin = {
|
|
|
var counters = [];
|
|
|
|
|
|
// Count and save element of each collection
|
|
|
+ var highestCounterRegexp = new RegExp('_([0-9])+$');
|
|
|
jQuery(subject).find('[data-prototype]').each(function() {
|
|
|
var collection = jQuery(this);
|
|
|
- counters[collection.attr('id')] = collection.children().length-1;
|
|
|
+ var counter = 0;
|
|
|
+ collection.children().each(function() {
|
|
|
+ var matches = highestCounterRegexp.exec(jQuery(this).find('.form-control').attr('id'));
|
|
|
+ if (matches && matches[1] && matches[1] > counter) {
|
|
|
+ counter = matches[1];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ counters[collection.attr('id')] = counter;
|
|
|
});
|
|
|
|
|
|
jQuery(subject).on('click', '.sonata-collection-add', function(event) {
|