diff --git a/src/front/src/components/vote/VoteConstructor.vue b/src/front/src/components/vote/VoteConstructor.vue index b7810cf92..78caae4de 100644 --- a/src/front/src/components/vote/VoteConstructor.vue +++ b/src/front/src/components/vote/VoteConstructor.vue @@ -142,13 +142,29 @@
- - - + + + + +
@@ -425,17 +441,37 @@ export default { const errorMessage = ref(""); + const validateAnswers = () => { + return form.value.questions.some((question) => { + if (question.settings.choice === "free") { + return question.answers.some( + (answer) => !answer.text || answer.text.trim() === "" + ); + } + return false; + }); + }; + const saveVoting = async () => { const hasEmptyQuestions = quests.value.includes(false); - if (!form.value.title || !form.value.description || form.value.questions.length < 1 || hasEmptyQuestions) { - errorMessage.value = "Все обязательные поля должны быть заполнены"; + const hasInvalidAnswers = validateAnswers(); + + if ( + !form.value.title || + !form.value.description || + form.value.questions.length < 1 || + hasEmptyQuestions || + hasInvalidAnswers + ) { + errorMessage.value = "Все обязательные поля и ответы должны быть заполнены"; return; } + try { const response = await createVote(form.value); console.log("Голосование успешно создано:", response); isVoteCreated.value = true; - emit('updating', 'active'); + emit("updating", "active"); } catch (error) { console.error("Ошибка при создании голосования:", error); } @@ -469,8 +505,7 @@ export default { ); watch(form.value, () => { - const hasEmptyQuestions = quests.value.includes(false); - if (!form.value.title || !form.value.description || form.value.questions.length < 1 || hasEmptyQuestions) { + if (!form.value.title || !form.value.description || form.value.questions.length < 1) { errorMessage.value = "Все обязательные поля должны быть заполнены"; } else { errorMessage.value = ""; @@ -483,12 +518,20 @@ export default { watch(() => form.value.questions, updateQuests, { deep: true }); - watch(() => form.value.questions, (newQuestions) => { - const hasEmptyQuestions = newQuestions.some((q) => !q.text || q.text.trim() === ""); - errorMessage.value = hasEmptyQuestions - ? "Все вопросы должны быть заполнены" - : ""; - }, { deep: true }); + watch( + () => form.value.questions, + (newQuestions) => { + const hasEmptyQuestions = newQuestions.some((q) => !q.text || q.text.trim() === ""); + const hasInvalidAnswers = validateAnswers(); + + if (hasEmptyQuestions || hasInvalidAnswers) { + errorMessage.value = "Все вопросы и ответы должны быть заполнены"; + } else { + errorMessage.value = ""; + } + }, + { deep: true } + ); watch(selectedTimeStart, () => { diff --git a/src/front/src/components/vote/VoteResult.vue b/src/front/src/components/vote/VoteResult.vue index f48e5df08..744a5f365 100644 --- a/src/front/src/components/vote/VoteResult.vue +++ b/src/front/src/components/vote/VoteResult.vue @@ -1,5 +1,5 @@