From c4f3ec98409641f159fe9fd322aa2bae4a1e43ad Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 10 Feb 2023 14:12:33 -0700 Subject: [PATCH] Et2Select: Fix free entries can get doubled if more free entries added --- api/js/etemplate/Et2Select/Et2SelectEmail.ts | 6 ++---- api/js/etemplate/Et2Select/SearchMixin.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2SelectEmail.ts b/api/js/etemplate/Et2Select/Et2SelectEmail.ts index 17996ca55a..d7265a5f43 100644 --- a/api/js/etemplate/Et2Select/Et2SelectEmail.ts +++ b/api/js/etemplate/Et2Select/Et2SelectEmail.ts @@ -97,14 +97,12 @@ export class Et2SelectEmail extends Et2Select accept: `.et2-select-draggable`, ondrop: function(e) { + // Add in as free entry e.target.createFreeEntry(e.draggable.target.value); - e.target.classList.remove('et2_toolbarDropArea'); + e.target.classList.remove('et2_dropZone'); // remove the dragged value from its origin source e.draggable.parent_node.value = e.draggable.parent_node.value.filter(_item => {return e.draggable.target.value !== _item;}) - - // set value for newly dropped target - e.target.value.push(e.draggable.target.value); }, ondragenter: function(e) { diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 1b0f3e3cc8..20be157edd 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -511,19 +511,22 @@ export const Et2WithSearchMixin = >(superclass { let options = []; - if(this.allowFreeEntries) - { - this.freeEntries.forEach((item) => - { - options.push({value: item.value, label: item.textContent, class: item.classList.toString()}); - }) - } // Any provided options options = options.concat(this.__select_options); // Any kept remote options options = options.concat(this._selected_remote); + if(this.allowFreeEntries) + { + this.freeEntries.forEach((item : SlMenuItem) => + { + if(!options.some(i => i.value == item.value)) + { + options.push({value: item.value, label: item.textContent, class: item.classList.toString()}); + } + }) + } return options; }