2022-10-26 22:37:41 +02:00
|
|
|
const form = document.getElementById("ratingForm");
|
|
|
|
const ratingSpan = document.getElementById("ratingSpan");
|
2022-10-27 23:52:21 +02:00
|
|
|
const buttonSubmit = document.getElementById("buttonSubmit");
|
2022-10-26 22:37:41 +02:00
|
|
|
|
2022-10-27 22:07:25 +02:00
|
|
|
const frontSection = document.getElementById("rating-component-front");
|
|
|
|
const backSection = document.getElementById("rating-component-back");
|
|
|
|
|
2022-10-26 22:37:41 +02:00
|
|
|
console.log(form);
|
|
|
|
|
|
|
|
form.addEventListener(
|
|
|
|
"submit",
|
|
|
|
(event) => {
|
|
|
|
const data = new FormData(form);
|
|
|
|
let output = "";
|
|
|
|
for (const entry of data) {
|
|
|
|
output = `${entry[1]}`;
|
|
|
|
}
|
|
|
|
ratingSpan.innerText = output;
|
|
|
|
|
|
|
|
//hide first section, make second section visible
|
2022-10-27 23:52:21 +02:00
|
|
|
if (output != "") {
|
|
|
|
frontSection.classList.add("hidden");
|
|
|
|
backSection.classList.remove("hidden");
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
Blur is used to remove the focus from the button that
|
|
|
|
we prevent from working because the user didn't select
|
|
|
|
a rating. Should probably add an error message, even
|
|
|
|
though its not in the design spec.
|
|
|
|
*/
|
|
|
|
buttonSubmit.blur();
|
|
|
|
}
|
2022-10-26 22:37:41 +02:00
|
|
|
//use a transition effect, plus a reduced motion version
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|