From 1e3108d23ed0628f8e1e4ecc706c2bd4ee95b7d7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 26 Oct 2021 15:09:36 +0200 Subject: [PATCH] wait #4831 @7 --- src/public/bunchmultiple/bunchmultiple.js | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/public/bunchmultiple/bunchmultiple.js b/src/public/bunchmultiple/bunchmultiple.js index cf9856d..5c187ff 100644 --- a/src/public/bunchmultiple/bunchmultiple.js +++ b/src/public/bunchmultiple/bunchmultiple.js @@ -13,12 +13,14 @@ 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 () { @@ -145,8 +147,6 @@ this.initItem(); } - console.log('removed', item); - var $this = this; setTimeout(function () { $this.updateAndChange(); @@ -160,6 +160,7 @@ }, initItem: function (values) { + console.log('initItem', values); var $this = this; var collapsed = true; var isNew = false; @@ -177,18 +178,27 @@ $(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) { -- 2.39.5