LP1831390: Don't clobber startId of combobox with null values user/sandbergja/lp1831390-ang-form-control-value-accessor-3
authorJane Sandberg <sandbej@linnbenton.edu>
Fri, 26 Jul 2019 18:28:13 +0000 (11:28 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Fri, 26 Jul 2019 18:48:46 +0000 (11:48 -0700)
Also ensures that writeValue accepts only ComboboxEntry values,
so [(ngModel)] both gives and receives ComboboxEntry values, rather
than a confusing mix.

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index d391244..355bdf3 100644 (file)
@@ -267,9 +267,10 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
         );
     }
 
-    writeValue(value: any) {
-        if (value !== undefined) {
-            this.startId = value;
+    writeValue(value: ComboboxEntry) {
+        if (value !== undefined && value !== null) {
+            this.startId = value.id;
+            this.applySelection();
         }
     }
 
index 3f00f20..e2dfe1f 100644 (file)
         </eg-org-family-select>
         The best libraries are: {{bestOnes.value | json}}
         <hr>
-        <eg-combobox ngModel #templateEntry="ngModel" [allowFreeText]="true">
+        <eg-combobox [(ngModel)]="kingdom" [allowFreeText]="true">
           <eg-combobox-entry entryId="Bacteria"></eg-combobox-entry>
           <eg-combobox-entry entryId="Archaea"></eg-combobox-entry>
           <eg-combobox-entry entryId="Protozoa"></eg-combobox-entry>
           <eg-combobox-entry entryId="Fungi"></eg-combobox-entry>
           <eg-combobox-entry entryId="Animalia"></eg-combobox-entry>
         </eg-combobox>
-      Result: {{templateEntry.value | json}}
+      Result: {{kingdom | json}}
         <hr>
         <eg-date-select [(ngModel)]="dateObject">
         </eg-date-select>
index ce45df8..3b7b9b7 100644 (file)
@@ -68,6 +68,7 @@ export class SandboxComponent implements OnInit {
     dateObject: Date = new Date();
 
     simpleCombo: ComboboxEntry;
+    kingdom: ComboboxEntry;
 
     complimentEvergreen: (rows: IdlObject[]) => void;
     notOneSelectedRow: (rows: IdlObject[]) => boolean;
@@ -126,6 +127,8 @@ export class SandboxComponent implements OnInit {
             this.toast.success('You chose: ' + l.label);
         });
 
+        this.kingdom = {id: 'Bacteria', label: 'Bacteria'};
+
         this.gridDataSource.data = [
             {name: 'Jane', state: 'AZ'},
             {name: 'Al', state: 'CA'},