From d93c0a9219a1b4e033840045fc507cc2f0b4b191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Fri, 15 Oct 2021 12:21:59 +0200 Subject: [PATCH] allow filling only one option --- .../feature_type/FeatureTypeCustomForm.vue | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/components/feature_type/FeatureTypeCustomForm.vue b/src/components/feature_type/FeatureTypeCustomForm.vue index 08b77649..27c3828f 100644 --- a/src/components/feature_type/FeatureTypeCustomForm.vue +++ b/src/components/feature_type/FeatureTypeCustomForm.vue @@ -231,13 +231,8 @@ export default { }, // * create an array, because backend expects an array set(newValue) { - this.form.options.errors = []; this.form.options.value = this.trimWhiteSpace(newValue).split(","); - if (this.hasDuplicates(this.form.options.value)) { - this.form.options.errors = [ - "Veuillez saisir des valeurs différentes", - ]; - } else { + if (!this.hasDuplicateOptions()) { this.updateStore(); } }, @@ -245,8 +240,16 @@ export default { }, methods: { - hasDuplicates(array) { - return new Set(array).size !== array.length; + hasDuplicateOptions() { + this.form.options.errors = []; + const isDup = + new Set(this.form.options.value).size !== + this.form.options.value.length; + if (isDup) { + this.form.options.errors = ["Veuillez saisir des valeurs différentes"]; + return true; + } + return false; }, fillCustomFormData(customFormData) { for (let el in customFormData) { @@ -300,15 +303,24 @@ export default { return occurences.length === 1; }, + checkFilledOptions() { + if (this.form.field_type.value === "list") { + if (this.form.options.value.length < 1) { + return false; + } else if ( + this.form.options.value.length === 1 && + this.form.options.value[0] === "" + ) { + return false; + } + } + return true; + }, + checkCustomForm() { this.form.label.errors = []; this.form.name.errors = []; this.form.options.errors = []; - console.log( - this.form.field_type.value, - this.form.field_type.value === "list", - this.form.options.value.length < 2 - ); if (!this.form.label.value) { //* vérifier que le label est renseigné this.form.label.errors = ["Veuillez compléter ce champ."]; @@ -329,13 +341,13 @@ export default { "Les champs personnalisés ne peuvent pas avoir des noms similaires.", ]; return false; - } else if ( - this.form.field_type.value === "list" && - this.form.options.value.length < 2 - ) { + } else if (!this.checkFilledOptions()) { //* s'il s'agit d'un type liste, vérifier que le champ option est bien renseigné this.form.options.errors = ["Veuillez compléter ce champ."]; return false; + } else if (this.hasDuplicateOptions()) { + //* pour le cas d'options dupliqués + return false; } return true; }, -- GitLab