diff --git a/src/components/feature_type/FeatureTypeCustomForm.vue b/src/components/feature_type/FeatureTypeCustomForm.vue index 08b77649d2cd65edd15cbf2ce4d6c09e5c107ead..27c3828fc60bdf73e6aa76c7a1fee99fb486e50d 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; },