Browse Source

improve v-autocompletes to take special cars into account

Olivier Massot 4 years ago
parent
commit
b8213bb360
1 changed files with 25 additions and 0 deletions
  1. 25 0
      pages/structures/index.vue

+ 25 - 0
pages/structures/index.vue

@@ -86,6 +86,7 @@
                         filled
                         hide-details
                         hide-no-data
+                        :filter="enhancedAutocompleteFilter"
                         @change="search"
                       />
                     </v-col>
@@ -99,6 +100,7 @@
                         filled
                         hide-details
                         hide-no-data
+                        :filter="enhancedAutocompleteFilter"
                         @change="search"
                       />
                     </v-col>
@@ -112,6 +114,7 @@
                         filled
                         hide-details
                         hide-no-data
+                        :filter="enhancedAutocompleteFilter"
                         @change="search"
                       />
                     </v-col>
@@ -514,6 +517,28 @@ export default Vue.extend({
     search (): void {
       this.filteredStructures = this.structures.filter((s) => { return this.matchFilters(s) })
       this.fitMapToResults()
+    },
+    autocompleteSearchNormalize (s: string): string {
+      return s
+        .toLowerCase()
+        .replace(/[éèẽëê]/g, 'e')
+        .replace(/[ç]/g, 'c')
+        .replace(/[îïĩ]/g, 'i')
+        .replace(/[àã]/g, 'a')
+        .replace(/[öôõ]/g, 'o')
+        .replace(/[ûüũ]/g, 'u')
+        .replace(/[-]/g, ' ')
+        .trim()
+    },
+    /**
+     * Enhanced filter for v-autocomplete components
+     *
+     * @param _
+     * @param queryText
+     * @param itemText
+     */
+    enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
+      return this.autocompleteSearchNormalize(itemText).includes(this.autocompleteSearchNormalize(queryText))
     }
   }
 })