From 10540ccf2c8fb05007c1c18656244108448bcca3 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 24 Mar 2021 15:35:16 -0400 Subject: [PATCH] LP1904036 org-select fires onChange on cleared values Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/share/org-select/org-select.component.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 50ea2212ae..352cb7ef80 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 @@ -43,7 +43,24 @@ export class OrgSelectComponent implements OnInit { showCombinedNames = false; // Managed via user/workstation setting - 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[] = []; @@ -286,8 +303,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)); -- 2.11.0