-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
92 lines (77 loc) · 2.81 KB
/
script.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
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
const dropdownBtn = document.querySelector('.dropdown__btn');
const dropdownBtnTitle = document.querySelector('.dropdown__title');
const dropdownBtnIcon = document.querySelector('.dropdown__icon');
const dropdownList = document.querySelector('.dropdown__list');
const dropdownItem = document.querySelectorAll('.dropdown__item');
let dropdownValue = 'option'
dropdownBtn.addEventListener('click', () => {
dropdownList.classList.toggle('dropdown__list-active')
dropdownBtnIcon.classList.toggle('dropdown__icon-active')
dropdownBtn.classList.toggle('dropdown__btn-active')
})
function closeDropdown(){
dropdownList.classList.remove('dropdown__list-active')
dropdownBtnIcon.classList.remove('dropdown__icon-active')
dropdownBtn.classList.remove('dropdown__btn-active')
}
function resetDropdonItems() {
dropdownItem.forEach(item => {
item.classList.remove('dropdown__item-active')
})
}
dropdownItem.forEach(item =>
item.addEventListener('click', () => {
dropdownValue = item.getAttribute('data-value')
dropdownBtnTitle.textContent = item.textContent;
resetDropdonItems();
item.classList.add('dropdown__item-active');
closeDropdown();
})
)
window.addEventListener('click', (e) => {
e.stopPropagation()
if (e.target !== dropdownBtn && e.target !== dropdownItem) {
closeDropdown()
}
})
/// creating result
const username = document.getElementById('username');
const password = document.getElementById('password');
const checkbox = document.getElementById('checkbox');
const toggle = document.getElementById('toggle');
const errorPassword = document.querySelector('.error-password')
const buttonNext = document.querySelector('.buttons__item-next');
let result = {}
function checkInputs(){
if (username.value && password.value) {
buttonNext.disabled = false
} else {
buttonNext.disabled = true
}
}
username.addEventListener('input', () => {
checkInputs()
})
password.addEventListener('input', () => {
checkInputs()
})
function collectJSON(){
result.username = username.value
result.password = password.value
result.remember = checkbox.checked
result.toggle = toggle.checked
result.radioSelection = document.querySelector('input[name="radio"]:checked').value
result.dropdown = dropdownValue
}
buttonNext.addEventListener('click', (e) => {
e.preventDefault()
errorPassword.classList.remove('error-active')
password.classList.remove('form__input-error')
if (password.value.length < 4 || password.value.length > 12) {
errorPassword.classList.add('error-active')
password.classList.add('form__input-error')
return
}
collectJSON()
alert(JSON.stringify(result))
})