]> _ Git - cubist_cms-back.git/commitdiff
wait #4831 @7
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Oct 2021 13:09:36 +0000 (15:09 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Oct 2021 13:09:36 +0000 (15:09 +0200)
src/public/bunchmultiple/bunchmultiple.js

index cf9856d3c9b4c720bccbcedc1db64c6ff2434c0b..5c187ff21b7ee9019ba2c228689ecea597b35ba5 100644 (file)
             this.cleanTemplate();
 
             var initValues = this.element.data('values');
-            $.each(initValues, function (k, v) {
-                $this.initItem(v);
-            });
+
 
             if (initValues.length === 0) {
                 this.initItem();
+            } else {
+                $.each(initValues, function (k, v) {
+                    $this.initItem(v);
+                });
             }
 
             this.element.on('click', '.additem' + this.bmidselector, function () {
                 this.initItem();
             }
 
-            console.log('removed', item);
-
             var $this = this;
             setTimeout(function () {
                 $this.updateAndChange();
         },
 
         initItem: function (values) {
+            console.log('initItem', values);
             var $this = this;
             var collapsed = true;
             var isNew = false;
                 $(item).addClass('collapsed');
             }
             // Handle nested multiple bunch
+            var nested = [];
             $(item).find('.subform>.bunchmultiple').each(function () {
                 var newrand = $this.id + '_' + Math.round(Math.random() * 10000000);
                 var sampleId = $(this).attr('id');
                 var html = replaceAll(sampleId, newrand, $(this).html());
                 $(this).html(html);
-                $(this).attr('id', newrand)
+                $(this).attr('id', newrand);
+                nested.push(newrand);
             });
 
             $(this.element).find(".bunchmultiple__items" + this.bmidselector).append($(item));
             this.setValues(item, values);
 
-            $(item).find('.subform>.bunchmultiple').bunchmultiple();
+
+            $.each(nested, function (k, v) {
+                if (isNew) {
+                    $('#' + v).find('.item:not(.sample)').remove();
+                }
+                $("#" + v).bunchmultiple();
+            });
+
 
             $(item).find('.form-group').find('input, select, .dropzone, textarea').each(function () {
                 if ($(this).closest('.bunchmultiple').attr('id') !== $this.id) {