From c0ac4cafae905120dbe9eae3855062331f682ab1 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 19 Dec 2024 11:35:10 -0700 Subject: [PATCH] Et2Select / SearchMixin: fix some more allowFreeEntry issues - existing values were not being properly matched - " freeEntry " option.class (with spaces) was causing nasty error in LitElement --- api/js/etemplate/Et2Select/Et2Select.ts | 15 +++++++++++++-- api/js/etemplate/Et2Select/SearchMixin.ts | 7 +++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index bba3638587..44cd4215fe 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -311,6 +311,9 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) private __value : string | string[] = ""; + // Flag to avoid issues with free entries & fix_bad_value + private __inInitialSetup : boolean = true; + protected tagOverflowObserver : IntersectionObserver = null; protected get dropdown() { return this.select; } @@ -429,6 +432,10 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) } // If no value is set, choose the first option // Only do this on once during initial setup, or it can be impossible to clear the value + if(!this.__inInitialSetup) + { + return; + } // value not in options --> use emptyLabel, if exists, or first option otherwise if(this.select_options.filter((option) => valueArray.find(val => val == option.value) || @@ -562,7 +569,11 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) super.loadFromXML(_node); // Wait for update to be complete before we check for bad value so extending selects can have a chance - this.updateComplete.then(() => this.fix_bad_value()); + this.updateComplete.then(() => + { + this.fix_bad_value(); + this.__inInitialSetup = false; + }); } /** @param changedProperties */ @@ -935,7 +946,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) // Tag used must match this.optionTag, but you can't use the variable directly. // Pass option along so SearchMixin can grab it if needed const value = (option.value).replaceAll(" ", "___"); - const classes = option.class ? Object.fromEntries((option.class).split(" ").map(k => [k, true])) : {}; + const classes = option.class ? Object.fromEntries((option.class).trim().split(" ").map(k => [k, true])) : {}; return html` async getUpdateComplete() { - const result = super.getUpdateComplete(); + const result = await super.getUpdateComplete(); if(this._searchInputNode) { await this._searchInputNode.updateComplete; @@ -358,8 +358,7 @@ export const Et2WithSearchMixin = dedupeMixin( if(changedProperties.has("value") && this.value) { // Overridden to add options if allowFreeEntries=true - if(this.allowFreeEntries && typeof this.value == "string" && !this.select_options.find(o => o.value == this.value && - (!o.class || o.class && !o.class.includes('remote')))) + if(this.allowFreeEntries && typeof this.value == "string" && !this.select_options.find(o => o.value == this.value)) { this.createFreeEntry(this.value); } @@ -1564,7 +1563,7 @@ export const Et2WithSearchMixin = dedupeMixin( this.value = value; } this.select_options = this.select_options.filter(v => v.value !== original); - this.dropdown.querySelector(".freeEntry[value='" + original.replace(/'/g, "\\\'") + "']").remove(); + this.dropdown.querySelector(".freeEntry[value='" + original.replace(/'/g, "\\\'") + "']")?.remove(); } if(value && value != original)