From c9eaa0fbda5ca651bf3451e3e457e06aaa9fa01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Mon, 13 Dec 2021 16:20:29 +0100 Subject: [PATCH] validate form on comment post --- src/views/feature/Feature_detail.vue | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue index 9a8b3e83..9098d81f 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -251,7 +251,11 @@ <label :for="comment_form.comment.id_for_label" >Ajouter un commentaire</label > - {{ comment_form.comment.errors }} + <ul v-if="comment_form.comment.errors" class="errorlist"> + <li> + {{ comment_form.comment.errors }} + </li> + </ul> <textarea v-model="comment_form.comment.value" :name="comment_form.comment.html_name" @@ -384,7 +388,7 @@ export default { comment: { id_for_label: "add-comment", html_name: "add-comment", - errors: null, + errors: "", value: null, }, non_field_errors: [], @@ -467,8 +471,18 @@ export default { this.addFeatureToMap(); }, + validateForm() { + this.comment_form.comment.errors = "" + if (!this.comment_form.comment.value) { + this.comment_form.comment.errors = "Ce champ est obligatoire." + return false; + } + return true; + }, + postComment() { - featureAPI + if (this.validateForm()) { + featureAPI .postComment({ featureId: this.$route.params.slug_signal, comment: this.comment_form.comment.value, @@ -490,6 +504,7 @@ export default { this.confirmComment(); } }); + } }, confirmComment() { -- GitLab