Browse Source

bug fix: sapi search form: term from autocomplete was not cleaned when typed was changing in field

bach 3 years ago
parent
commit
30998980ca

+ 1 - 1
web/modules/custom/materio_sapi/src/Form/MaterioSapiSearchForm.php

@@ -31,7 +31,7 @@ class MaterioSapiSearchForm extends FormBase {
       '#attributes' => [
         "placeholder" => $this->t('Search'),
         // "@keyup" => "keyup",
-        "@keyup.enter" => "submit",
+        // "@keyup.enter" => "submit",
         "v-model" => "typed",
         "v-focus" => "",
         // "v-on:select" => "typed",

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


+ 17 - 5
web/themes/custom/materiotheme/vuejs/components/Form/SearchForm.vue

@@ -25,7 +25,7 @@ export default {
   },
   methods: {
     submit() {
-      console.log("search clicked", this.typed, this.autocomplete);
+      console.log("search submited", this.typed, this.autocomplete);
       // New search is triggered by Base.vue with router (which will also fill the store)
       this.$router.push({name:'base', query:{keys:this.typed,term:this.autocomplete}})
       // this.$router.push({
@@ -35,9 +35,16 @@ export default {
     },
     onAutoCompleteSelect(event, ui){
       event.preventDefault();
-      // console.log('autoCompleteSelect', event, ui);
+      console.log('autoCompleteSelect', event, ui);
       this.typed = ui.item.label
-      this.autocomplete = ui.item.value
+      setTimeout(function(){
+        console.log('update autocomplete value after settimeout');
+        this.autocomplete = ui.item.value
+        if(this.typed !== this.keys && this.autocomplete !== this.term){
+          this.submit()
+        }
+      }.bind(this), 1)
+
     }
   },
   directives: {
@@ -60,12 +67,17 @@ export default {
     }
   },
   watch: {
+    typed(n, o){
+      console.log('typed changed', o, n);
+      // is changed also when autocomplete change it ...
+      this.autocomplete = null
+    },
     keys(n, o){
-      console.log('keys changed', n, o);
+      console.log('keys changed', o, n);
       this.typed = n
     },
     term(n, o){
-      console.log('autocomplete changed', n, o);
+      console.log('autocomplete changed', o, n);
       this.autocomplete = n
     }
   },

Some files were not shown because too many files changed in this diff