Browse Source

Fix issue with adding new elements in an array field. The offset starts
at 0 and not at 1, however the code was adding elements at the nth+1
element. Example:

Existing:
0: asdf
1: hjkl

Add element did this:
0: asdf
1: hjkl
3: <new element>

With this patch it should do this:
0: asdf
1: hjkl
2: <new element>

Matthew J Mucklo 12 năm trước cách đây
mục cha
commit
df2310cc1a
1 tập tin đã thay đổi với 2 bổ sung2 xóa
  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');