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});
}
}
@Input() startId: any;
@Input() set entries(el: ComboboxEntry[]) {
- this.addEntries(el);
+ this.entrylist = el;
+ this.applySelection();
}
// Emitted when the value is changed via UI.
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() {
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;
}
<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 ----------------------------- -->
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'
gridDataSource: GridDataSource = new GridDataSource();
- taEntries: TypeaheadEntry[];
+ taEntries: ComboboxEntry[];
btSource: GridDataSource = new GridDataSource();
world = 'world'; // for local template version