From fa2375b1a6a910f40ab4b4e293755ae14f90399f Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 5 Dec 2022 13:56:31 -0700 Subject: [PATCH] SearchMixin: Fix selected remote options got lost if adding a freeEntry --- api/js/etemplate/Et2Select/SearchMixin.ts | 39 +++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 98b87eb435..7fefef616f 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -12,6 +12,7 @@ import {css, html, LitElement, render, SlotMixin} from "@lion/core"; import {cleanSelectOptions, SelectOption} from "./FindSelectOptions"; import {Validator} from "@lion/form-core"; import {Et2Tag} from "./Tag/Et2Tag"; +import {SlMenuItem} from "@shoelace-style/shoelace"; // Otherwise import gets stripped let keep_import : Et2Tag; @@ -478,7 +479,7 @@ export const Et2WithSearchMixin = >(superclass return this.querySelectorAll(this.optionTag + ".freeEntry"); } - get search_options() : SelectOption[] + get select_options() : SelectOption[] { let options = []; @@ -490,7 +491,7 @@ export const Et2WithSearchMixin = >(superclass }) } // Any provided options - options = options.concat(this.__search_options); + options = options.concat(this.__select_options); // Any kept remote options options = options.concat(this._selected_remote); @@ -498,6 +499,12 @@ export const Et2WithSearchMixin = >(superclass return options; } + set select_options(options : SelectOption[]) + { + this.__select_options = options; + this.requestUpdate('select_options'); + } + get value() { return super.value; @@ -789,21 +796,21 @@ export const Et2WithSearchMixin = >(superclass async _handleSearchBlur(event : FocusEvent) { clearTimeout(this._searchTimeout); - if(event.relatedTarget && [this, this.dropdown].indexOf((event.relatedTarget).parentElement) == -1 || - event.relatedTarget === null - ) + if(event.relatedTarget && event.relatedTarget instanceof SlMenuItem) { - // Try any value they had in progress - if(this._searchInputNode.value && this.allowFreeEntries) - { - this.createFreeEntry(this._searchInputNode.value); - } - await this.dropdown.hide(); - this.clearSearch(); - if(event.relatedTarget && event.relatedTarget !== this) - { - event.relatedTarget.focus(); - } + return; + } + + // Try any value they had in progress + if(this._searchInputNode.value && this.allowFreeEntries) + { + this.createFreeEntry(this._searchInputNode.value); + } + await this.dropdown.hide(); + this.clearSearch(); + if(event.relatedTarget && event.relatedTarget !== this) + { + event.relatedTarget.focus(); } }