combobox: teach it how to start with a selected value when IDL-based
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 20 Jan 2020 17:12:53 +0000 (12:12 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 20 Jan 2020 17:12:53 +0000 (12:12 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts

index 3d98604..8c1d1e6 100644 (file)
@@ -68,6 +68,7 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
     // onChange() is NOT fired when applying the default value,
     // unless startIdFiresOnChange is set to true.
     @Input() startId: any = null;
+    @Input() idlClass: string;
     @Input() startIdFiresOnChange: boolean;
 
     // Allow the selected entry ID to be passed via the template
@@ -82,6 +83,16 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
                 // It's possible the selected ID lives in a set of entries
                 // that are yet to be provided.
                 this.startId = id;
+                if (this.idlClass) {
+                    this.pcrud.retrieve(this.idlClass, id)
+                    .subscribe(rec => {
+                        this.entrylist = [{
+                            id: id,
+                            label: rec[this.idlField]()
+                        }];
+                        this.selected = this.entrylist.filter(e => e.id === id)[0];
+                    });
+                }
             }
         }
     }
@@ -90,7 +101,6 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
         return this.selected ? this.selected.id : null;
     }
 
-    @Input() idlClass: string;
     @Input() idlField: string;
     @Input() idlIncludeLibraryInLabel: string;
     @Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;