LP1840050 Combobox reset on new entries
authorBill Erickson <berickxx@gmail.com>
Thu, 15 Aug 2019 15:40:06 +0000 (11:40 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 16 Aug 2019 20:40:32 +0000 (16:40 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts

index de6831a..9e7dc25 100644 (file)
@@ -75,11 +75,16 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
         if (id) { 
             if (this.entrylist.length) {
                 this.selected = this.entrylist.filter(e => e.id === id)[0];
-            } else {
+            }
+
+            if (!this.selected) {
+                // It's possible the selected ID lives in a set of entries
+                // that are yet to be provided.
                 this.startId = id;
             }
         }
     }
+
     get selectedId(): any {
         return this.selected ? this.selected.id : null;
     }
@@ -103,6 +108,9 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
     @Input() set entries(el: ComboboxEntry[]) {
         if (el) {
             this.entrylist = el;
+
+            // new set of entries essentially means a new instance. reset.
+            this.defaultSelectionApplied = false;
             this.applySelection();
 
             // It's possible to provide an entrylist at load time, but
@@ -187,8 +195,6 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
         if (this.startId &&
             this.entrylist && !this.defaultSelectionApplied) {
 
-            console.log('applyg select ' + this.startId);
-
             const entry =
                 this.entrylist.filter(e => e.id === this.startId)[0];