From: Bill Erickson Date: Mon, 2 Jul 2018 14:50:10 +0000 (-0400) Subject: LP#1775466 Combobox repairs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9c26785cd195106bb6594f07684ab1839f27a44b;p=working%2FEvergreen.git LP#1775466 Combobox repairs Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox-entry.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox-entry.component.ts index 1238d8a5fe..059a4398c9 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox-entry.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox-entry.component.ts @@ -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}); } } diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts index d929d62c18..e08369f2d7 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts @@ -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; } diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 8f95b19d90..84fb330d4a 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -39,7 +39,7 @@
- Typeahead: +
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index d3f749aa6a..0d428da4c6 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -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