LP1929741 Combobox supports startsWith search
authorBill Erickson <berickxx@gmail.com>
Tue, 22 Jun 2021 15:42:00 +0000 (11:42 -0400)
committerJane Sandberg <js7389@princeton.edu>
Sun, 2 Oct 2022 15:02:49 +0000 (08:02 -0700)
In lieu of the default behavor of the typeahead, which does a 'contains'
search.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts

index 5c70ced..243458c 100644 (file)
@@ -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;
+                    }
                 });
             })
         );