From e5662d67c0f1531a4d51ad8fa6aa7e58812e07a9 Mon Sep 17 00:00:00 2001
From: florent <flavelle@neogeo.fr>
Date: Tue, 13 Sep 2022 09:30:49 +0200
Subject: [PATCH] fix for multiple prerecorded fields

---
 .../Feature/Edit/FeatureExtraForm.vue         | 42 ++++++++++++-------
 src/store/modules/feature-type.store.js       | 11 +++--
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/src/components/Feature/Edit/FeatureExtraForm.vue b/src/components/Feature/Edit/FeatureExtraForm.vue
index e0e63f4c..92aef035 100644
--- a/src/components/Feature/Edit/FeatureExtraForm.vue
+++ b/src/components/Feature/Edit/FeatureExtraForm.vue
@@ -63,7 +63,9 @@
     </label>
     <Multiselect
       v-model="selectedPrerecordedValue"
-      :options="selectedPrerecordedListValues"
+      :options="
+        selectedPrerecordedListValues[field.options[0]] ? selectedPrerecordedListValues[field.options[0]] : []
+      "
       :options-limit="10"
       :allow-empty="!field.is_mandatory"
       track-by="label"
@@ -295,26 +297,34 @@ export default {
       }
     },
     prerecordedListSearchQuery(newValue) {
-      if (newValue) {
-        this.loadingPrerecordedListValues = true;
-        this.GET_SELECTED_PRERECORDED_LIST_VALUES({
-          name: this.field.options[0],
-          pattern: newValue
+      this.loadingPrerecordedListValues = true;
+      this.GET_SELECTED_PRERECORDED_LIST_VALUES({
+        name: this.field.options[0],
+        pattern: newValue
+      })
+        .then(() => {
+          this.loadingPrerecordedListValues = false;
         })
-          .then(() => {
-            this.loadingPrerecordedListValues = false;
-          })
-          .catch(() => {
-            this.loadingPrerecordedListValues = false;
-          });
-      } else {
-        this.SET_SELECTED_PRERECORDED_LIST_VALUES([]);
-      }
+        .catch(() => {
+          this.loadingPrerecordedListValues = false;
+        });
     }
   },
 
   created() {
-    console.log(this.field.value);
+    if (this.field.field_type === 'pre_recorded_list') {
+      this.loadingPrerecordedListValues = true;
+      this.GET_SELECTED_PRERECORDED_LIST_VALUES({
+        name: this.field.options[0],
+        pattern: ''
+      })
+        .then(() => {
+          this.loadingPrerecordedListValues = false;
+        })
+        .catch(() => {
+          this.loadingPrerecordedListValues = false;
+        });
+    }
     if (this.field.value) {
       this.selectedPrerecordedValue = { label: this.field.value };
     }
diff --git a/src/store/modules/feature-type.store.js b/src/store/modules/feature-type.store.js
index 1b04fa29..b3c26bef 100644
--- a/src/store/modules/feature-type.store.js
+++ b/src/store/modules/feature-type.store.js
@@ -31,7 +31,7 @@ const feature_type = {
     fileToImport: null,
     importFeatureTypeData: [],
     preRecordedLists: [],
-    selectedPrerecordedListValues: []
+    selectedPrerecordedListValues: {}
   },
 
   getters: {
@@ -88,8 +88,8 @@ const feature_type = {
     SET_PRERECORDED_LISTS(state, payload) {
       state.preRecordedLists = payload;
     },
-    SET_SELECTED_PRERECORDED_LIST_VALUES(state, payload) {
-      state.selectedPrerecordedListValues = payload.slice(0, 10).map(el => { return { label: el };});
+    SET_SELECTED_PRERECORDED_LIST_VALUES(state, { name, values }) {
+      state.selectedPrerecordedListValues[name] = values.slice(0, 10).map(el => { return { label: el };});
     }
   },
 
@@ -127,7 +127,10 @@ const feature_type = {
           `${this.state.configuration.VUE_APP_DJANGO_API_BASE}prerecorded-list-values/${name}/?pattern=${pattern}`
         );
         if (response.status === 200) {
-          commit('SET_SELECTED_PRERECORDED_LIST_VALUES', response.data);
+          commit('SET_SELECTED_PRERECORDED_LIST_VALUES', {
+            name: name,
+            values: response.data
+          });
         }
       } catch (err) {
         console.error(err);
-- 
GitLab