From 69f0f20085b892929827be4560b7686616fc050a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Thu, 7 Oct 2021 17:40:20 +0200
Subject: [PATCH] check unique custom form names, display errors & fix leaflet
 background color

---
 src/App.vue                                   |  5 ++++
 .../feature_type/FeatureTypeCustomForm.vue    | 29 +++++++++++++++++--
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/App.vue b/src/App.vue
index 2c345237..9378a4c3 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -264,6 +264,11 @@ footer {
   flex-direction: column;
   justify-content: center;
 }
+
+.leaflet-container {
+  background: white !important;
+}
+
 @media screen and (min-width: 560px) {
   .mobile {
     display: none !important;
diff --git a/src/components/feature_type/FeatureTypeCustomForm.vue b/src/components/feature_type/FeatureTypeCustomForm.vue
index 83ac53b0..39d1349e 100644
--- a/src/components/feature_type/FeatureTypeCustomForm.vue
+++ b/src/components/feature_type/FeatureTypeCustomForm.vue
@@ -283,6 +283,28 @@ export default {
       return true;
     },
 
+    checkUniqueName() {
+      console.log(this.$store);
+      console.log(this.$store.state);
+      console.log(this.$store.state.feature_type);
+      if (this.form.name.value) {
+        const occurences = this.$store.state.feature_type.customForms
+          .map((el) => el.name)
+          .filter((el) => el === this.form.name.value);
+        console.log("occurences", occurences);
+        console.log(occurences.length);
+        if (occurences.length > 1) {
+          console.log("duplicate", this.form.name.value);
+          this.form.name.errors = [
+            "Les champs personnalisés ne peuvent pas avoir des noms similaires.",
+          ];
+          return false;
+        }
+      }
+      this.form.name.errors = [];
+      return true;
+    },
+
     checkCustomForm() {
       if (this.form.label.value === null) {
         this.form.label.errors = ["Veuillez compléter ce champ."];
@@ -297,10 +319,11 @@ export default {
         ];
         this.form.label.errors = [];
         return false;
+      } else if (this.checkUniqueName()) {
+        this.form.label.errors = [];
+        this.form.name.errors = [];
+        return true;
       }
-      this.form.label.errors = [];
-      this.form.name.errors = [];
-      return true;
     },
   },
 
-- 
GitLab