From f551f48ab84b87264b468aa2a3ebb494b885d742 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 22 Jun 2021 11:42:00 -0400 Subject: [PATCH] LP1929741 Combobox supports startsWith search In lieu of the default behavor of the typeahead, which does a 'contains' search. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 7ddd3eda00..3a27ff8500 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 @@ -75,6 +75,10 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie // If true, applies form-control-sm CSS @Input() smallFormControl = false; + // If true, the typeahead only matches values that start with + // the value typed as opposed to a 'contains' match. + @Input() startsWith = false; + // Add a 'required' attribute to the input isRequired: boolean; @Input() set required(r: boolean) { @@ -517,7 +521,11 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie // text entered. return this.entrylist.filter(entry => { const label = entry.label || entry.id; - return label.toLowerCase().indexOf(term.toLowerCase()) > -1; + if (this.startsWith) { + return label.toLowerCase().startsWith(term.toLowerCase()); + } else { + return label.toLowerCase().indexOf(term.toLowerCase()) > -1; + } }); }) ); -- 2.11.0