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

prevent sending form if duplicate & empty string in fields

parent 579e06e6
No related branches found
No related tags found
No related merge requests found
......@@ -284,46 +284,37 @@ export default {
},
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;
const occurences = this.$store.state.feature_type.customForms
.map((el) => el.name)
.filter((el) => el === this.form.name.value);
return occurences.length === 1;
},
checkCustomForm() {
if (this.form.label.value === null) {
this.form.label.errors = [];
this.form.name.errors = [];
if (!this.form.label.value) {
//* vérifier que le label est renseigné
this.form.label.errors = ["Veuillez compléter ce champ."];
return false;
} else if (this.form.name.value === null) {
} else if (!this.form.name.value) {
//* vérifier que le nom est renseigné
this.form.name.errors = ["Veuillez compléter ce champ."];
this.form.label.errors = [];
return false;
} else if (!this.hasRegularCharacters(this.form.name.value)) {
//* vérifier qu'il n'y a pas de caractères spéciaux
this.form.name.errors = [
"Veuillez utiliser seulement les caratères autorisés.",
];
this.form.label.errors = [];
return false;
} else if (this.checkUniqueName()) {
this.form.label.errors = [];
this.form.name.errors = [];
return true;
} else if (!this.checkUniqueName()) {
//* vérifier si les noms sont pas dupliqués
this.form.name.errors = [
"Les champs personnalisés ne peuvent pas avoir des noms similaires.",
];
return false;
}
return true;
},
},
......
......@@ -153,7 +153,6 @@
<i class="white save icon"></i>
Créer et importer le(s) signalement(s) du geojson
</button>
</form>
</div>
</div>
......@@ -345,13 +344,14 @@ export default {
},
checkCustomForms() {
let is_valid = true;
if (this.$refs.customForms)
for (const customForm of this.$refs.customForms) {
if (customForm.checkCustomForm() === false) {
return false;
is_valid = false;
}
}
return true; //* fallback if all customForms returned true
return is_valid; //* fallback if all customForms returned true
},
checkForms() {
......
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