From 46b172c88e4f87caeb74cfc139f5861e13526c84 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 6 Jul 2022 11:20:53 -0600 Subject: [PATCH] Et2Select: In some cases the change event from the search input was triggering an extra widget change event --- api/js/etemplate/Et2Select/Et2Select.ts | 1 - api/js/etemplate/Et2Select/SearchMixin.ts | 20 +++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index ef0745eb58..9c7086445a 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -146,7 +146,6 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) this.updateComplete.then(() => { - this.addEventListener("sl-clear", this._triggerChange) this.addEventListener("sl-change", this._triggerChange); this.addEventListener("sl-after-show", this._doResize) }); diff --git a/api/js/etemplate/Et2Select/SearchMixin.ts b/api/js/etemplate/Et2Select/SearchMixin.ts index 23e800ac1a..558f56c25a 100644 --- a/api/js/etemplate/Et2Select/SearchMixin.ts +++ b/api/js/etemplate/Et2Select/SearchMixin.ts @@ -448,18 +448,16 @@ export const Et2WithSearchMixin = >(superclass this.addEventListener("sl-blur", this._handleSearchAbort); this.addEventListener("sl-select", this._handleSelect); this.addEventListener("sl-clear", this._handleClear) - if(this._oldChange && this.onchange) + this.updateComplete.then(() => { - this.updateComplete.then(() => - { - // Search messes up event order. Since it throws its own bubbling change event, - // selecting an option fires 2 change events - 1 before the widget is finished adjusting, losing the value - // We catch all change events, then call this._oldChange only when value changes - this.removeEventListener("change", this._oldChange); - this.addEventListener("change", this._handleChange); - }); - } - + // Search messes up event order. Since it throws its own bubbling change event, + // selecting an option fires 2 change events - 1 before the widget is finished adjusting, losing the value + // We catch all change events, then call this._oldChange only when value changes + this.removeEventListener("change", this._oldChange); + // Need our own change to catch the change event from search input + this.addEventListener("change", this._handleChange); + }); + this._searchButtonNode.addEventListener("click", this._handleSearchButtonClick); }