소스 검색

Merge pull request #957 from netounet/patch-5

Fix collection nested javascript
Thomas 12 년 전
부모
커밋
0841db3290
1개의 변경된 파일9개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 1
      Resources/public/base.js

+ 9 - 1
Resources/public/base.js

@@ -156,7 +156,15 @@ var Admin = {
 
             var container = jQuery(this).closest('[data-prototype]');
             var proto = container.attr('data-prototype');
-            proto = proto.replace(/__name__/g, container.children().length);
+            // Set field id
+            var idRegexp = new RegExp(container.attr('id')+'___name__','g');
+            proto = proto.replace(idRegexp, container.attr('id')+'_'+container.children().length);
+            
+            // 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);
+            jQuery(proto).insertBefore(jQuery(this).parent());
             jQuery(proto).insertBefore(jQuery(this).parent());
             
             jQuery(this).trigger('sonata-collection-item-added');