From bd1e7c40301570946940bc6541cd4cb2722a6c68 Mon Sep 17 00:00:00 2001 From: Simon C Date: Tue, 2 May 2023 23:11:13 +0200 Subject: [PATCH] feat: Ajout du design de la calculette --- src/components/Question.vue | 96 +++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 21 deletions(-) diff --git a/src/components/Question.vue b/src/components/Question.vue index 694cc05..20822be 100644 --- a/src/components/Question.vue +++ b/src/components/Question.vue @@ -31,8 +31,30 @@ const displayPopup = ref(false); function showHidePopup() { displayPopup.value = !displayPopup.value; } -const h = ref(); -const d = ref(); +function validatePopup() { + const calcule = Math.round((h.value * 100) / d.value); + const regexp = /[^0-9]*([0-9]{2})/g; + const answersLength = props.question.answers.length; + const answerIndex = props.question.answers.find((answer, index) => { + const values = Array.from(answer.title.matchAll(regexp), (m) => m[1]); + if (values.length > 0) { + const min = values.length == 1 ? 0 : values[0]; + const max = values.length == 1 ? values[0] : values[1]; + if (calcule >= min && calcule <= max) { + return true; + } + } + if (answersLength == index + 1) { + return true; + } + }); + document.querySelector( + "input[id=" + `question_${props.question.id}_answer_${answerIndex.id}` + "]" + ).checked = true; + showHidePopup(); +} +const h = ref(0); +const d = ref(0); -