From a19d89ae3a95186a89af44e7bc788b36f93bb4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Fri, 30 Jun 2023 10:34:08 +0200 Subject: [PATCH] display more informative message on option field --- .../FeatureType/FeatureTypeCustomForm.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/FeatureType/FeatureTypeCustomForm.vue b/src/components/FeatureType/FeatureTypeCustomForm.vue index bdb0fc4f..07873b80 100644 --- a/src/components/FeatureType/FeatureTypeCustomForm.vue +++ b/src/components/FeatureType/FeatureTypeCustomForm.vue @@ -490,20 +490,23 @@ export default { return occurences.length === 1; }, - checkListOptions() { - if (!['list', 'pre_recorded_list'].includes(this.form.field_type.value)) return true; + checkOptions() { if (this.form.field_type.value === 'list') { - return this.form.options.value.length >= 2 && !this.form.options.value.includes(''); + return this.form.options.value.length >= 2 && !this.form.options.value.includes('') ? + '' : 'Veuillez renseigner au moins 2 options.'; } if (this.form.field_type.value === 'pre_recorded_list') { - return this.form.options.value.length === 1; + return this.form.options.value.length === 1 ? + '' : 'Veuillez renseigner une option.'; } + return ''; }, checkCustomForm() { this.form.label.errors = []; this.form.name.errors = []; this.form.options.errors = []; + const optionError = this.checkOptions(); let isValid = true; if (!this.form.label.value) { //* vérifier que le label est renseigné @@ -525,9 +528,9 @@ export default { 'Les champs personnalisés ne peuvent pas avoir des noms similaires.', ]; isValid = false; - } else if (!this.checkListOptions()) { + } else if (optionError) { //* 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.']; + this.form.options.errors = [optionError]; isValid = false; } else if (this.hasDuplicateOptions()) { //* pour le cas d'options dupliqués -- GitLab