LP#1775466 Combobox repairs
authorBill Erickson <berickxx@gmail.com>
Mon, 2 Jul 2018 14:50:10 +0000 (10:50 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 2 Jul 2018 14:50:10 +0000 (10:50 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/combobox/combobox-entry.component.ts
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 1238d8a..059a439 100644 (file)
@@ -17,8 +17,8 @@ export class ComboboxEntryComponent implements OnInit{
         if (this.selected) {
             this.combobox.startId = this.entryId;
         }
-        this.combobox.addEntries(
-            [{id: this.entryId, label: this.entryLabel}]);
+        this.combobox.addEntry(
+            {id: this.entryId, label: this.entryLabel});
     }
 }
 
index d929d62..e08369f 100644 (file)
@@ -52,7 +52,8 @@ export class ComboboxComponent implements OnInit {
     @Input() startId: any;
 
     @Input() set entries(el: ComboboxEntry[]) {
-        this.addEntries(el);
+        this.entrylist = el;
+        this.applySelection();
     }
 
     // Emitted when the value is changed via UI.
@@ -86,23 +87,22 @@ export class ComboboxComponent implements OnInit {
         setTimeout(() => this.click$.next(''));
     }
 
-    // Called by combobox-entry.component
-    addEntries(entries: ComboboxEntry[]) {
-        entries.forEach(entry => {
-
-            if (this.entrylist.filter(e => e.id === entry.id).length) {
-                // avoid dupes
-                return;
-            }
-
-            this.entrylist.push(entry);
-
-            if (this.startId === entry.id) {
-                this.selected = entry;
-            } else if (this.selectFirst && this.entrylist.length === 1) {
+    // Apply a default selection where needed
+    applySelection() {
+        if (this.startId) {
+            const entry = this.entrylist.filter(e => e.id === entry.id)[0];
+            if (entry) {
                 this.selected = entry;
             }
-        });
+        } else if (this.selectFirst) {
+            this.selected = this.entrylist[0];
+        }
+    }
+
+    // Called by combobox-entry.component
+    addEntry(entry: ComboboxEntry) {
+        this.entrylist.push(entry);
+        this.applySelection();
     }
 
     onBlur() {
@@ -121,7 +121,7 @@ export class ComboboxComponent implements OnInit {
                 this.selectorChanged(
                     {item: this.selected, preventDefault: () => true});
             } else {
-                // If free text is now allowed, clear the value when
+                // If free text is not allowed, clear the value when
                 // the user navigates away to avoid confusion.
                 this.selected = null;
             }
index 8f95b19..84fb330 100644 (file)
@@ -39,7 +39,7 @@
    <button class="btn btn-info" (click)="testToast()">Test Toast Message</button>
   </div>
   <div class="col-lg-4">
-    Typeahead: <eg-combobox [entries]="taEntries" [clickShowsAll]="true"></eg-combobox>
+    <eg-combobox [entries]="taEntries" placeholder="Combobox..."></eg-combobox>
   </div>
 </div>
 <!-- /Progress Dialog Experiments ----------------------------- -->
index d3f749a..0d428da 100644 (file)
@@ -13,7 +13,7 @@ import {OrgService} from '@eg/core/org.service';
 import {Pager} from '@eg/share/util/pager';
 import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
 import {PrintService} from '@eg/share/print/print.service';
-import {TypeaheadEntry} from '@eg/share/typeahead/typeahead.component';
+import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 
 @Component({
   templateUrl: 'sandbox.component.html'
@@ -33,7 +33,7 @@ export class SandboxComponent implements OnInit {
 
     gridDataSource: GridDataSource = new GridDataSource();
 
-    taEntries: TypeaheadEntry[];
+    taEntries: ComboboxEntry[];
 
     btSource: GridDataSource = new GridDataSource();
     world = 'world'; // for local template version