-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (31 loc) · 1.05 KB
/
Copy pathscript.js
File metadata and controls
43 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { conectApi } from "./conect.js";
localStorage.setItem("user", '');
localStorage.setItem("avaliation", 0);
// SUBMIT
const formulario = document.querySelector("[data-form]");
const botao = document.querySelector("[btn-submit]");
async function submitAvaliation(event) {
event.preventDefault();
botao.classList.add("submit-loading");
const name = document.querySelector("[data-name]").value;
const avaliation = valueAvaliation();
// -- ApiTwo
const body = {
"nome": name,
"avaliacao": Number(avaliation)
}
// -- ApiOne
// const body = {
// "name": name,
// "value": Number(avaliation)
// }
await conectApi.postAvaliation(body);
botao.classList.remove("submit-loading");
window.location.href = "/submited.html";
}
function valueAvaliation() {
const radios = document.getElementsByName("nota");
const choosedRadio = Array.from(radios).find(value => value.checked);
return choosedRadio.value;
}
formulario.addEventListener("submit", event => submitAvaliation(event));