From 364a5417b7822feae4dd304d635c85f70a74acdb Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 28 Feb 2022 11:33:49 +0100 Subject: [PATCH] wip #5127 @0.5 --- src/public/bunchmultiple/bunchmultiple.js | 22 ++++++++++++++----- .../views/fields/select2_from_array.blade.php | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/public/bunchmultiple/bunchmultiple.js b/src/public/bunchmultiple/bunchmultiple.js index 621c1da..49cdb2b 100644 --- a/src/public/bunchmultiple/bunchmultiple.js +++ b/src/public/bunchmultiple/bunchmultiple.js @@ -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 + '"]'; @@ -14,12 +15,11 @@ 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 + @@ -67,10 +65,17 @@ 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(); }, @@ -163,6 +171,9 @@ }, updateAndChange: function () { + if (!this.inited) { + return; + } this.update(); $(this.element).trigger('change'); }, @@ -198,7 +209,6 @@ $(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(); @@ -215,7 +225,7 @@ }); setTimeout(function () { - $this.setValues(item, values); + $this.setValues(item, values, false); $(document).trigger('cubist.bunchmultiple.added'); $($this).trigger('change'); }, 500); diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index 28e993c..9f1a74c 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -78,7 +78,7 @@ {{-- FIELD JS - will be loaded in the after_scripts section --}} @push('crud_fields_scripts') - +