Explorar el Código

Merge pull request #1033 from oodle/master

Fix issue with adding a new element to a Form element consisting of a collection / array
Thomas hace 12 años
padre
commit
db6ba5b387
Se han modificado 1 ficheros con 2 adiciones y 2 borrados
  1. 2 2
      Resources/public/base.js

+ 2 - 2
Resources/public/base.js

@@ -158,12 +158,12 @@ var Admin = {
             var proto = container.attr('data-prototype');
             // Set field id
             var idRegexp = new RegExp(container.attr('id')+'___name__','g');
-            proto = proto.replace(idRegexp, container.attr('id')+'_'+container.children().length);
+            proto = proto.replace(idRegexp, container.attr('id')+'_'+(container.children().length - 1));
             
             // Set field name
             var parts = container.attr('id').split('_');
             var nameRegexp = new RegExp(parts[parts.length-1]+'\\]\\[__name__','g');
-            proto = proto.replace(nameRegexp, parts[parts.length-1]+']['+container.children().length);
+            proto = proto.replace(nameRegexp, parts[parts.length-1]+']['+(container.children().length - 1));
             jQuery(proto).insertBefore(jQuery(this).parent());
             
             jQuery(this).trigger('sonata-collection-item-added');