-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (51 loc) · 1.5 KB
/
app.js
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
function animatedForm(){
const arrows = document.querySelectorAll('.fa-arrow-down');
arrows.forEach(arrow => {
arrow.addEventListener("click", () => {
const input = arrow.previousElementSibling;
const parent = arrow.parentElement;
const nextForm = parent.nextElementSibling;
//check for validation
if(input.type === "text" && validateUser(input)){
nextSlide(parent,nextForm);
}else if(input.type === 'email' && validateEmail(input)){
nextSlide(parent,nextForm);
}else if(input.type ==='password' && validateUser(input)){
nextSlide(parent,nextForm);
}else{
parent.style.animation = 'shake 0.5s ease'
}
//get rid of animation
parent.addEventListener('animationend', () =>{
parent.style.animation = '';
});
});
});
}
function validateUser(user){
if(user.value.length < 6 ){
console.log("not enough characters");
error("rgb(189,87,87)");
}else{
error("rgb(87, 189, 130)");
return true;
}
}
function error (color){
document.body.style.backgroundColor = color;
}
function validateEmail(email){
const validation = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ ;
if (validation.test(email.value)){
error("rgb(87, 189, 130)");
return true;
}else{
error("rgb(189,87,87)");
}
}
function nextSlide(parent,nextForm){
parent.classList.add('innactive');
parent.classList.remove('active');
nextForm.classList.add('active');
}
animatedForm();