48 lines
1.4 KiB
Vue
48 lines
1.4 KiB
Vue
<template>
|
|
<MainPoll :question-component="QuestionChoice" @submit="submitForm">
|
|
<template #submit>
|
|
<div id="error">{{ errorMessage }}</div>
|
|
<button id="form-submit" type="submit">Valider</button>
|
|
</template>
|
|
</MainPoll>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { MainPoll } from '#components';
|
|
import QuestionChoice from '~/components/QuestionChoice.vue';
|
|
|
|
|
|
const runtimeConfig = useRuntimeConfig()
|
|
|
|
const route = useRoute()
|
|
|
|
const errorMessage = ref("")
|
|
|
|
|
|
async function submitForm(e: Event) {
|
|
const target = e.target
|
|
if (!target || !(target instanceof HTMLFormElement)) {
|
|
throw Error("Form target not found")
|
|
}
|
|
const formObject = Object.fromEntries(new FormData(target))
|
|
const filtered = Object.keys(Object.fromEntries(Object.entries(formObject).filter(([key, value]) => value == "unset"
|
|
))).sort((a, b) => (Number(a) || Number(a[0])) - (Number(b) || Number(b[0])))
|
|
console.log(filtered)
|
|
if (filtered.length > 0) {
|
|
errorMessage.value = `Vous n'avez pas répondu à toutes les questions ! Veuillez répondre aux questions suivantes : ${filtered.join(", ")}`
|
|
return
|
|
}
|
|
await $fetch(`${runtimeConfig.public.apiBase}/vote/${route.query.code}`, {
|
|
method: "POST",
|
|
body: Object.fromEntries(new FormData(target))
|
|
})
|
|
|
|
navigateTo({ path: "/finished", query: route.query })
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
#error {
|
|
color: #E94A4D;
|
|
}
|
|
</style> |