Et2Email: Better handling of blur & showing validation error

This commit is contained in:
nathan 2023-12-20 10:33:09 -07:00
parent 7948a64d3c
commit a0e0d9cefb

View File

@ -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 = ((<SlOption>event.target).value).replaceAll("___", " ");
this.addAddress(value);
this._search.value = "";