From: Bill Erickson Date: Tue, 22 Jun 2021 15:42:00 +0000 (-0400) Subject: LP1929741 Combobox supports startsWith search X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d209158976466a420b4f9beb2917a9f135082c32;p=working%2FEvergreen.git 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 --- 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; + } }); }) );