LP1904036 org-select fires onChange on cleared values
authorBill Erickson <berickxx@gmail.com>
Wed, 24 Mar 2021 19:35:16 +0000 (15:35 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:28 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts

index 50ea221..352cb7e 100644 (file)
@@ -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<string>();
     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));