Skip to content
Snippets Groups Projects
Commit d93c0a92 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

allow filling only one option

parent 1d644223
No related branches found
No related tags found
1 merge request!118REDMINE_ISSUE-12064
...@@ -231,13 +231,8 @@ export default { ...@@ -231,13 +231,8 @@ export default {
}, },
// * create an array, because backend expects an array // * create an array, because backend expects an array
set(newValue) { set(newValue) {
this.form.options.errors = [];
this.form.options.value = this.trimWhiteSpace(newValue).split(","); this.form.options.value = this.trimWhiteSpace(newValue).split(",");
if (this.hasDuplicates(this.form.options.value)) { if (!this.hasDuplicateOptions()) {
this.form.options.errors = [
"Veuillez saisir des valeurs différentes",
];
} else {
this.updateStore(); this.updateStore();
} }
}, },
...@@ -245,8 +240,16 @@ export default { ...@@ -245,8 +240,16 @@ export default {
}, },
methods: { methods: {
hasDuplicates(array) { hasDuplicateOptions() {
return new Set(array).size !== array.length; 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) { fillCustomFormData(customFormData) {
for (let el in customFormData) { for (let el in customFormData) {
...@@ -300,15 +303,24 @@ export default { ...@@ -300,15 +303,24 @@ export default {
return occurences.length === 1; 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() { checkCustomForm() {
this.form.label.errors = []; this.form.label.errors = [];
this.form.name.errors = []; this.form.name.errors = [];
this.form.options.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) { if (!this.form.label.value) {
//* vérifier que le label est renseigné //* vérifier que le label est renseigné
this.form.label.errors = ["Veuillez compléter ce champ."]; this.form.label.errors = ["Veuillez compléter ce champ."];
...@@ -329,13 +341,13 @@ export default { ...@@ -329,13 +341,13 @@ export default {
"Les champs personnalisés ne peuvent pas avoir des noms similaires.", "Les champs personnalisés ne peuvent pas avoir des noms similaires.",
]; ];
return false; return false;
} else if ( } else if (!this.checkFilledOptions()) {
this.form.field_type.value === "list" &&
this.form.options.value.length < 2
) {
//* s'il s'agit d'un type liste, vérifier que le champ option est bien renseigné //* 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 = ["Veuillez compléter ce champ."];
return false; return false;
} else if (this.hasDuplicateOptions()) {
//* pour le cas d'options dupliqués
return false;
} }
return true; return true;
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment