-<!-- todo disabled -->
<ng-template #defaultDisplayTemplate let-r="result">
-{{r.label || r.id}}
+ <span id="{{domId}}-{{r.id}}">{{r.label}}</span>
</ng-template>
<ng-template #acqfTemplate egIdlClass="acqf" let-r="result">
- {{r.fm.code()}} ({{r.fm.year()}}) ({{getOrgShortname(r.fm.org())}})
+ <span id="{{domId}}-{{r.id}}">{{r.fm.code()}} ({{r.fm.year()}}) ({{getOrgShortname(r.fm.org())}})</span>
</ng-template>
<ng-template #acplTemplate egIdlClass="acpl" let-r="result">
- {{r.fm.name()}} ({{getOrgShortname(r.fm.owning_lib())}})
+ <span id="{{domId}}-{{r.id}}">
+ {{r.fm.name()}} ({{getOrgShortname(r.fm.owning_lib())}})
+ </span>
</ng-template>
<div class="d-flex">
freetext?: boolean;
userdata?: any; // opaque external value; ignored by this component.
fm?: IdlObject;
+ disabled?: boolean;
}
@Directive({
this.isRequired = r;
}
+ // Array of entry identifiers to disable in the selector
+ @Input() disableEntries: any[] = [];
+
// Disable the input
isDisabled: boolean;
@Input() set disabled(d: boolean) {
this.entrylist = [{
id: id,
label: this.getFmRecordLabel(rec),
- fm: rec
+ fm: rec,
+ disabled : this.disableEntries.includes(id)
}];
this.selected = this.entrylist.filter(e => e.id === id)[0];
});
});
}
+ // NgbTypeahead doesn't offer a way to style the dropdown
+ // button directly, so we have to reach up and style it ourselves.
+ applyDisableStyle() {
+ this.disableEntries.forEach(id => {
+ const node = document.getElementById(`${this.domId}-${id}`);
+ if (node) {
+ const button = node.parentNode as HTMLElement;
+ button.classList.add('disabled');
+ }
+ });
+ }
+
filter = (text$: Observable<string>): Observable<ComboboxEntry[]> => {
return text$.pipe(
debounceTime(200),
if (this.asyncDataSource) {
term = '';
} else {
+ // Give the typeahead a chance to open before applying
+ // the disabled entry styling.
+ setTimeout(() => this.applyDisableStyle());
return this.entrylist;
}
}
+ // Give the typeahead a chance to open before applying
+ // the disabled entry styling.
+ setTimeout(() => this.applyDisableStyle());
+
// Filter entrylist whose labels substring-match the
// text entered.
return this.entrylist.filter(entry => {