From 0dcea1760657ca25f9ce84c27ed3c2d1b1091979 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 2 Jul 2018 11:40:47 -0400 Subject: [PATCH] LP#1775466 Combobox repairs Signed-off-by: Bill Erickson --- .../src/app/share/combobox/combobox.component.html | 1 + .../src/app/share/combobox/combobox.component.ts | 24 ++++++++++++++++++++-- .../src/app/staff/sandbox/sandbox.component.html | 3 ++- .../eg2/src/app/staff/sandbox/sandbox.component.ts | 8 ++++---- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html index 879a02340c..5c31968143 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html @@ -7,6 +7,7 @@
+ * + * + */ import {Component, OnInit, Input, Output, ViewChild, EventEmitter, ElementRef} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {map} from 'rxjs/operators/map'; @@ -51,6 +56,9 @@ export class ComboboxComponent implements OnInit { // onChange() is NOT fired when applying the default value @Input() startId: any; + // True if a default selection has been made. + defaultSelectionApplied: boolean; + @Input() set entries(el: ComboboxEntry[]) { this.entrylist = el; this.applySelection(); @@ -71,6 +79,7 @@ export class ComboboxComponent implements OnInit { this.click$ = new Subject(); this.onChange = new EventEmitter(); this.freeTextId = -1; + this.defaultSelectionApplied = false; this.formatDisplayString = (result: ComboboxEntry) => { return result.label.trim(); @@ -89,13 +98,25 @@ export class ComboboxComponent implements OnInit { // Apply a default selection where needed applySelection() { + + if (this.defaultSelectionApplied + || !this.entrylist || this.entrylist.length === 0) { + // Avoid unnecessary processing. Also as the page renders, + // the entrylist may be empty at times, avoid any attempts + // to apply selection during that time + return; + } + if (this.startId) { - const entry = this.entrylist.filter(e => e.id === entry.id)[0]; + const entry = + this.entrylist.filter(e => e.id === this.startId)[0]; if (entry) { this.selected = entry; + this.defaultSelectionApplied = true; } } else if (this.selectFirst) { this.selected = this.entrylist[0]; + this.defaultSelectionApplied = true; } } @@ -132,7 +153,6 @@ export class ComboboxComponent implements OnInit { // This only fires when an item in the list is selected, not when // the value is cleared or free-text is used. selectorChanged(selEvent: NgbTypeaheadSelectItemEvent) { - console.log('selector changed'); this.onChange.emit(selEvent.item.id); } 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 84fb330d4a..739184d6df 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,8 @@
- +
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 0d428da4c6..9151b1fcde 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 @@ -58,8 +58,6 @@ export class SandboxComponent implements OnInit { private toast: ToastService, private printer: PrintService ) { - - this.taEntries = []; } ngOnInit() { @@ -71,8 +69,10 @@ export class SandboxComponent implements OnInit { ]; this.pcrud.retrieveAll('cmrcfld', {order_by:{cmrcfld: 'name'}}) - .subscribe(format => - this.taEntries.push({id: format.id(), label: format.name()})); + .subscribe(format => { + if (!this.taEntries) { this.taEntries = []; } + this.taEntries.push({id: format.id(), label: format.name()}) + }); this.btSource.getRows = (pager: Pager, sort: any[]) => { -- 2.11.0