]> _ Git - cubist_cms-back.git/commitdiff
wip #5127 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Feb 2022 10:33:49 +0000 (11:33 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Feb 2022 10:33:49 +0000 (11:33 +0100)
src/public/bunchmultiple/bunchmultiple.js
src/resources/views/fields/select2_from_array.blade.php

index 621c1dade7f05192e9039657a79c980485e10570..49cdb2b1090806b06ac4299cab10f2faeeaa301b 100644 (file)
@@ -6,6 +6,7 @@
 
     JQbunchmultiple.prototype = {
         init: function () {
+            this.inited = false;
             var $this = this;
             this.id = $(this.element).attr('id');
             this.bmidselector = '[data-bmid="' + this.id + '"]';
 
             var initValues = this.element.data('values');
 
-
             if (initValues.length === 0) {
                 this.initItem();
             } else {
                 $.each(initValues, function (k, v) {
-                    $this.initItem(v);
+                    $this.initItem(v, true);
                 });
             }
 
@@ -47,8 +47,6 @@
                 return false;
             });
 
-            this.initSort();
-
             this.element.on('change', 'input' + this.bmidselector +
                 ',select' + this.bmidselector +
                 ',textarea' + this.bmidselector +
                 return true;
             });
 
+            this.initSort();
+
             if ($(this.element).parent().closest('.bunchmultiple').length === 0) {
                 $(this.element).find('.bunchmultiple__wrapper:eq(0)').addClass('bunchmultiple_root');
                 $(this.element).addClass('bunchmultiple_root');
             }
+
+            setTimeout(function () {
+                $this.inited = true;
+                $this.updateAndChange();
+            }, 1000);
         },
 
         cleanTemplate: function () {
@@ -78,6 +83,9 @@
         },
 
         update: function () {
+            if (!this.inited) {
+                return;
+            }
             this.serialize();
             this.updateLegends();
         },
         },
 
         updateAndChange: function () {
+            if (!this.inited) {
+                return;
+            }
             this.update();
             $(this.element).trigger('change');
         },
             $(this.element).find(".bunchmultiple__items" + this.bmidselector).append($(item));
             this.setValues(item, values);
 
-
             $.each(nested, function (k, v) {
                 if (isNew) {
                     $('#' + v).find('.item:not(.sample)').remove();
             });
 
             setTimeout(function () {
-                $this.setValues(item, values);
+                $this.setValues(item, values, false);
                 $(document).trigger('cubist.bunchmultiple.added');
                 $($this).trigger('change');
             }, 500);
index 28e993c6b133f5018a900ca23919c09f88c44731..9f1a74cc6d4596c4a38c5a5e5dd9521b0ee3ed21 100644 (file)
@@ -78,7 +78,7 @@
 
     {{-- FIELD JS - will be loaded in the after_scripts section --}}
     @push('crud_fields_scripts')
-        <!-- include select2 js-->
+        <!-- include select2 js -->
         <script src="{{ asset('packages/select2/dist/js/select2.min.js') }}"></script>
         <script>
             jQuery(document).ready(function ($) {