]> _ Git - cubist_cms-back.git/commitdiff
wait #7713 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 Sep 2025 12:26:11 +0000 (14:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 Sep 2025 12:26:11 +0000 (14:26 +0200)
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/select2_from_array.blade.php

index e0bccd0387371935c7cc03ade216c2323a6bda24..28221b4fed7b110a92dbec9bc8bb9510845041d5 100644 (file)
@@ -6,6 +6,7 @@
 
     JQbunchmultiple.prototype = {
         init: function () {
+            this.addItemTriggerTimeout;
             this.inited = false;
             var $this = this;
             this.id = $(this.element).attr('id');
@@ -65,6 +66,7 @@
                     }, 10);
                 } else {
                     item.removeClass('collapsed');
+                    $(document).trigger('cubist.bunchmultiple.openitem');
                 }
                 return false;
             });
         },
 
         initItem: function (values) {
-
+            clearTimeout(this.addItemTriggerTimeout);
             var $this = this;
             var collapsed = true;
             var isNew = false;
                 $(this).attr('data-bmid', $this.id);
             });
 
-            setTimeout(function () {
+            this.addItemTriggerTimeout = setTimeout(function () {
                 $this.setValues(item, values, false);
                 $(document).trigger('cubist.bunchmultiple.added');
                 $($this).trigger('change');
-            }, 10);
+            }, 100);
         },
 
         setValues(item, values) {
index d8785673f6453a31702e93087267ae06f56421b6..6ffdc5ef9d2c39f7df18a45c99210c72cd0f9faa 100644 (file)
@@ -112,6 +112,9 @@ if($ajax){
                 $(document).on('cubist.bunchmultiple.added', function () {
                     initUntriggeredSelectFromArray($);
                 });
+                $(document).on('cubist.bunchmultiple.openitem', function () {
+                    initUntriggeredSelectFromArray($);
+                });
                 initUntriggeredSelectFromArray($);
 
                 $(document).on('change', '.select2_from_array', function () {
@@ -127,9 +130,11 @@ if($ajax){
             }
 
             function initUntriggeredSelectFromArray($) {
+                let j = 0;
+
                 // trigger select2 for each untriggered select2 box
-                $('.select2_from_array:not(.select2-hidden-accessible)').each(function (i, obj) {
-                    if ($(obj).closest('.item.sample').length > 0) {
+                $('.select2_from_array:not(.select2-hidden-accessible):visible:not(.init)').each(function (i, obj) {
+                    if ($(obj).closest('.item.sample,.item.collapsed').length > 0) {
                         return;
                     }
                     var options = {
@@ -149,7 +154,11 @@ if($ajax){
                         }
                     }
                     $(obj).addClass('init').select2(options);
+                    j++;
                 });
+                if (j > 0) {
+                    console.log('initUntriggeredSelectFromArray', j);
+                }
                 showSelectedValue();
             }
         </script>