From d04bd942bcf8512765777d79de3b3cd5f64f3aa7 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 Signed-off-by: Galen Charlton --- 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 5c70ced2ee..243458cc71 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 @@ -76,6 +76,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) { @@ -560,7 +564,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