-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
111 lines (75 loc) · 2.38 KB
/
Copy pathscript.js
File metadata and controls
111 lines (75 loc) · 2.38 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const form = document.getElementById("form");
const username = document.getElementById("username")
const email = document.getElementById("email")
const password = document.getElementById("password")
const passwordConfirmation = document.getElementById("password-confirmation");
form.addEventListener("submit", (event) => {
event.preventDefault();
checkForm();
})
email.addEventListener("blur", () => {
checkInputEmail();
})
username.addEventListener("blur", () => {
checkInputUsername();
})
function checkInputUsername(){
const usernameValue = username.value;
if(usernameValue === ""){
errorInput(username, "Preencha um username!")
}else{
const formItem = username.parentElement;
formItem.className = "form-content"
}
}
function checkInputEmail(){
const emailValue = email.value;
if(emailValue === ""){
errorInput(email, "O email é obrigatório.")
}else{
const formItem = email.parentElement;
formItem.className = "form-content"
}
}
function checkInputPassword(){
const passwordValue = password.value;
if(passwordValue === ""){
errorInput(password, "A senha é obrigatória.")
}else if(passwordValue.length < 8){
errorInput(password, "A senha precisa ter no mínimo 8 caracteres.")
}else{
const formItem = password.parentElement;
formItem.className = "form-content"
}
}
function checkInputPasswordConfirmation(){
const passwordValue = password.value;
const confirmationPasswordValue = passwordConfirmation.value;
if(confirmationPasswordValue === ""){
errorInput(passwordConfirmation, "A confirmação de senha é obrigatória.")
}else if(confirmationPasswordValue !== passwordValue){
errorInput(passwordConfirmation, "As senhas não são iguais.")
}else{
const formItem = passwordConfirmation.parentElement;
formItem.className = "form-content"
}
}
function checkForm(){
checkInputUsername();
checkInputEmail();
checkInputPassword();
checkInputPasswordConfirmation();
const formItems = form.querySelectorAll(".form-content")
const isValid = [...formItems].every( (item) => {
return item.className === "form-content"
});
if(isValid){
alert("CADASTRADO COM SUCESSO!")
}
}
function errorInput(input, message){
const formItem = input.parentElement;
const textMessage = formItem.querySelector("a")
textMessage.innerText = message;
formItem.className = "form-content error"
}