LP1929741 Item location select starts with; hide Unset
authorBill Erickson <berickxx@gmail.com>
Tue, 22 Jun 2021 18:47:44 +0000 (14:47 -0400)
committerJane Sandberg <js7389@princeton.edu>
Sun, 2 Oct 2022 15:02:49 +0000 (08:02 -0700)
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/item-location-select/item-location-select.component.html
Open-ILS/src/eg2/src/app/share/item-location-select/item-location-select.component.ts
Open-ILS/src/eg2/src/app/staff/acq/lineitem/copy-attrs.component.html

index d452fa7..eae6d05 100644 (file)
@@ -15,6 +15,7 @@
   [displayTemplate]="displayTemplate"
   (onChange)="cboxChanged($event)"
   [required]="required"
+  [startsWith]="startsWith"
   (blur)="propagateTouch()"
   placeholder="Shelving Location..."
   i18n-placeholder>
index cd99267..33edf71 100644 (file)
@@ -77,6 +77,14 @@ export class ItemLocationSelectComponent
     // the typeahead
     @Input() readOnly = false;
 
+    // See combobox
+    @Input() startsWith = false;
+
+    // Show <Unset> when no value is applied.
+    // This only applies to non-required fields, since <Unset> would
+    // trick the combobox into thinking a valid value had been applied
+    @Input() showUnsetString = true;
+
     @ViewChild('comboBox', {static: false}) comboBox: ComboboxComponent;
     @ViewChild('unsetString', {static: false}) unsetString: StringComponent;
 
@@ -147,7 +155,7 @@ export class ItemLocationSelectComponent
 
         const entries: ComboboxEntry[] = [];
 
-        if (!this.required) {
+        if (!this.required && this.showUnsetString) {
             entries.push({id: null, label: this.unsetString.text});
         }
 
@@ -161,8 +169,9 @@ export class ItemLocationSelectComponent
     }
 
     getLocationsAsync(term: string): Observable<ComboboxEntry> {
+        // "1" is ignored, but a value is needed for pipe() below
+        let obs = of([1]);
 
-        let obs = of();
         if (!this.filterOrgsApplied) {
             // Apply filter orgs the first time they are needed.
             obs = from(this.setFilterOrgs());
@@ -177,9 +186,11 @@ export class ItemLocationSelectComponent
             return of();
         }
 
+        const ilike = this.startsWith ? `${term}%` : `%${term}%`;
+
         const search: any = {
             deleted: 'f',
-            name: {'ilike': `%${term}%`}
+            name: {'ilike': ilike}
         };
 
         if (this.startId) {
@@ -195,7 +206,7 @@ export class ItemLocationSelectComponent
         }
 
         return new Observable<ComboboxEntry>(observer => {
-            if (!this.required) {
+            if (!this.required && this.showUnsetString) {
                 observer.next({id: null, label: this.unsetString.text});
             }
 
index 623584b..43f13b3 100644 (file)
     </eg-org-select>
   </div>  
   <div class="flex-1 p-1">
-    <eg-item-location-select  [readOnly]="fieldIsDisabled('location')"
-      #locationSelector [ngModel]="copy.location()"
+    <eg-item-location-select [readOnly]="fieldIsDisabled('location')"
+      #locationSelector [ngModel]="copy.location()" [startsWith]="true"
       (valueChange)="valueChange('location', $event)"
-      permFilter="CREATE_PICKLIST">                         
+      permFilter="CREATE_PICKLIST" [showUnsetString]="false">
     </eg-item-location-select>
   </div>
   <div class="flex-1 p-1">