1
0
mirror of https://github.com/EGroupware/egroupware.git synced 2025-01-03 20:49:08 +01:00

Et2Select: Fix change event got fired too early

Second attempt.  If fix_bad_value() made a change, that was triggering change event before Et2App.et2_ready() had been called.  Now making sure that event does not get fired.
This commit is contained in:
nathan 2022-11-08 11:04:03 -07:00
parent 67b22373f5
commit 4dffd24feb

View File

@ -159,12 +159,20 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
}
}
/**
* If fix_bad_value() has to change the value, the update will trigger a change event.
* We don't want that event to fire since it happens too soon, before the handler is ready and app.ts has set up
* @type {boolean}
* @private
*/
private _block_change_event = false;
constructor(...args : any[])
{
super();
// We want this on more often than off
this.hoist = true;
this._triggerChange = this._triggerChange.bind(this);
this._doResize = this._doResize.bind(this);
this._handleMouseWheel = this._handleMouseWheel.bind(this);
@ -200,10 +208,14 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
_triggerChange(e)
{
if(super._triggerChange(e))
if(super._triggerChange(e) && !this._block_change_event)
{
this.dispatchEvent(new Event("change"));
}
if(this._block_change_event)
{
this.updateComplete.then(() => this._block_change_event = false);
}
}
/**
@ -272,6 +284,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
{
let oldValue = this.value;
this.value = this.emptyLabel ? "" : "" + this.select_options[0]?.value;
this._block_change_event = true;
// ""+ to cast value of 0 to "0", to not replace with ""
this.requestUpdate("value", oldValue);
}