From: Bill Erickson Date: Wed, 24 Mar 2021 19:35:16 +0000 (-0400) Subject: LP1904036 org-select fires onChange on cleared values X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9e2eaef1c800edff00c3c1ca0b0084b7e6901b43;p=working%2FEvergreen.git LP1904036 org-select fires onChange on cleared values Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts index 0c8a701bf0..ff08a9806c 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts @@ -41,7 +41,24 @@ interface OrgDisplay { export class OrgSelectComponent implements OnInit { static domId = 0; - selected: OrgDisplay; + _selected: OrgDisplay; + set selected(s: OrgDisplay) { + if (s !== this._selected) { + this._selected = s; + + // orgChanged() does not fire when the value is cleared, + // so emit the onChange here for cleared values only. + if (!s) { // may be '' or null + this._selected = null; + this.onChange.emit(null); + } + } + } + + get selected(): OrgDisplay { + return this._selected; + } + click$ = new Subject(); valueFromSetting: number = null; sortedOrgs: IdlObject[] = []; @@ -260,8 +277,6 @@ export class OrgSelectComponent implements OnInit { } // Fired by the typeahead to inform us of a change. - // TODO: this does not fire when the value is cleared :( -- implement - // change detection on this.selected to look specifically for NULL. orgChanged(selEvent: NgbTypeaheadSelectItemEvent) { // console.debug('org unit change occurred ' + selEvent.item); this.onChange.emit(this.org.get(selEvent.item.id));