LP1825851 Combobox display template option
authorBill Erickson <berickxx@gmail.com>
Fri, 12 Jul 2019 16:37:59 +0000 (12:37 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 12 Jul 2019 16:37:59 +0000 (12:37 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts

index 0a5deee..821244c 100644 (file)
@@ -1,6 +1,6 @@
 
 <!-- todo disabled -->
-<ng-template #displayTemplate let-r="result">
+<ng-template #defaultDisplayTemplate let-r="result">
 {{r.label || r.id}}
 </ng-template>
 
@@ -14,7 +14,7 @@
     [required]="isRequired"
     [(ngModel)]="selected" 
     [ngbTypeahead]="filter"
-    [resultTemplate]="displayTemplate"
+    [resultTemplate]=" displayTemplate || defaultDisplayTemplate"
     [inputFormatter]="formatDisplayString"
     (click)="click$.next($event.target.value)"
     (blur)="onBlur()"
index 63f964e..6995043 100644 (file)
@@ -3,7 +3,8 @@
  *  <!-- see also <eg-combobox-entry> -->
  * </eg-combobox>
  */
-import {Component, OnInit, Input, Output, ViewChild, EventEmitter, ElementRef} from '@angular/core';
+import {Component, OnInit, Input, Output, ViewChild, 
+    TemplateRef, EventEmitter, ElementRef} from '@angular/core';
 import {Observable, of, Subject} from 'rxjs';
 import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, merge, filter} from 'rxjs/operators';
 import {NgbTypeahead, NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
@@ -83,6 +84,9 @@ export class ComboboxComponent implements OnInit {
         }
     }
 
+    // When provided use this as the display template for each entry.
+    @Input() displayTemplate: TemplateRef<any>;
+
     // Emitted when the value is changed via UI.
     // When the UI value is cleared, null is emitted.
     @Output() onChange: EventEmitter<ComboboxEntry>;