From a0e0d9cefb2e892774fd2232954c829eaf64936e Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 20 Dec 2023 10:33:09 -0700 Subject: [PATCH] Et2Email: Better handling of blur & showing validation error --- api/js/etemplate/Et2Email/Et2Email.ts | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/api/js/etemplate/Et2Email/Et2Email.ts b/api/js/etemplate/Et2Email/Et2Email.ts index 08e401e965..33e566528f 100644 --- a/api/js/etemplate/Et2Email/Et2Email.ts +++ b/api/js/etemplate/Et2Email/Et2Email.ts @@ -491,13 +491,13 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI /** Hides the listbox. */ async hide() { - this.open = false; - this.requestUpdate("open"); if(!this.open || this.disabled) { return undefined; } + this.open = false; + this.requestUpdate("open"); return waitForEvent(this, 'sl-after-hide'); } @@ -660,20 +660,6 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI const path = event.composedPath(); if(this && !path.includes(this)) { - // If they had something OK typed, use it - if(this.addAddress(this._search.value.trim())) - { - this._search.value = ""; - } - else if(this._search.value) - { - // Invalid input, show message - // Can't just call this.validate() since the input is not part of the value - let currentValue = this.value; - this.value = [this._search.value]; - this.validate(); - this.value = currentValue; - } this.hide(); } }; @@ -803,6 +789,9 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI private handleSearchFocus() { + // Clear any manual message (errors on invalid search text) + this.set_validation_error(false); + this.hasFocus = true; // Should not be needed, but not firing the update this.requestUpdate("hasFocus"); @@ -813,7 +802,7 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI this._search.setSelectionRange(this._search.value.length, this._search.value.length); } - private handleSearchBlur() + private handleSearchBlur(event : FocusEvent) { this.hasFocus = false; // Should not be needed, but not firing the update @@ -1095,6 +1084,11 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI */ handleSuggestionsMouseUp(event : MouseEvent) { + if(typeof event.target.value == "undefined") + { + return; + } + const value = ((event.target).value).replaceAll("___", " "); this.addAddress(value); this._search.value = "";