From a076aba72854b14b4f2a4c6483e8052383ab6bb3 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 15 Feb 2024 11:54:57 -0700 Subject: [PATCH] Fix Et2Tree loses initial value getValue() needs to give back what is set by set_value() or whatever, even if the tree has not rendered yet. --- api/js/etemplate/Et2Tree/Et2Tree.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/api/js/etemplate/Et2Tree/Et2Tree.ts b/api/js/etemplate/Et2Tree/Et2Tree.ts index 7c3bd08861..2cdc002e9f 100644 --- a/api/js/etemplate/Et2Tree/Et2Tree.ts +++ b/api/js/etemplate/Et2Tree/Et2Tree.ts @@ -367,15 +367,6 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) return this._currentOption } - /** - * getValue, retrieves the Id of the selected Item - * @return string or object or null - */ - getValue(): string | string[] - { - return this._currentOption ? this._currentOption.id : null - } - /** * getSelectedNode, retrieves the full node of the selected Item * @return {SlTreeItem} full SlTreeItem @@ -598,7 +589,7 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) exportparts="checkbox" id=${selectOption.id} title=${selectOption.tooltip || nothing} - ?selected=${this.value.includes(selectOption.id)} + ?selected=${typeof this.value == "string" && this.value == selectOption.id || typeof this.value?.includes == "function" && this.value.includes(selectOption.id)} ?expanded=${(this.calculateExpandState(selectOption))} ?lazy=${selectOption.item?.length === 0 && selectOption.child} ?focused=${selectOption.focused || nothing} @@ -627,6 +618,8 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) (event: any) => { this._previousOption = this._currentOption ?? (this.value.length ? this.getNode(this.value) : null); this._currentOption = this.getNode(event.detail.selection[0].id); + const ids = event.detail.selection.map(i => i.id); + this.value = this.multiple ? ids ?? [] : ids[0] ?? ""; event.detail.previous = this._previousOption?.id; this._currentSlTreeItem = event.detail.selection[0]; if(typeof this.onclick == "function") @@ -757,6 +750,10 @@ export class Et2Tree extends Et2WidgetWithSelectMixin(LitElement) protected updated(_changedProperties: PropertyValues) { + // This is somehow required to set the autoload URL properly? + // TODO: Make this not needed, either this.autoload_url should be properly set or go away in favour of using this.autoload + this.createTree(); + this._link_actions(this.actions) super.updated(_changedProperties); }