Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Sep 23, 2023
2 parents d882c94 + 9495000 commit 2511764
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
6 changes: 4 additions & 2 deletions src/css/layout/07-leave.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
transition: border-color var(--transition-dur-and-func);
}

.leave__form-input:hover,
.leave__form-input:focus {
.leave__form-input:not(.invalid):hover,
.leave__form-input:not(.invalid):focus {
border-color: var(--color-green);
}

Expand Down Expand Up @@ -403,3 +403,5 @@
.invalid {
border-color: var(--color-invalid);
}


63 changes: 27 additions & 36 deletions src/js/form.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
const inputs = document.querySelectorAll('input[name^="user-"]');
const form = document.querySelector('.leave__feedback');

form.addEventListener('input', () => {
const feedbackState = {};
inputs.forEach(input => {
feedbackState[input.name.split('-')[1]] = input.value;
});
form.addEventListener('input', () => {
const feedbackState = {};
inputs.forEach(input => {
feedbackState[input.name.split('-')[1]] = input.value; });
});

inputs.forEach(input => {
input.addEventListener('blur', () => {
if (input.value.length > 0) {
input.classList.remove('invalid');
input.classList.add('valid');
}
inputs.forEach(input => {
input.addEventListener('blur', () => {
if (input.value.length > 0) {
input.classList.remove('invalid');
input.classList.add('valid');
}
});
});

form.addEventListener('submit', event => {
event.preventDefault();

let isValid = true;
inputs.forEach(input => {
if (input.value === '') {
input.classList.add('invalid');
isValid = false;
} else {
input.classList.remove('invalid');
input.value = '';
input.classList.remove('valid');
}
});

if (isValid) {
// Отримання об'єкта feedbackState зі значеннями полів форми
const feedbackState = {};
inputs.forEach(input => {
feedbackState[input.name.split('-')[1]] = input.value;
});

// Ваш код для подальшої обробки feedbackState
}
});
form.addEventListener('submit', event => {
event.preventDefault();
let isValid = true;
inputs.forEach(input => {
if (input.value === '') {
input.classList.add('invalid');
isValid = false;
} else {
input.classList.remove('invalid');
input.classList.remove('valid');
}
});
if (isValid) {
inputs.forEach(input => {
input.value = '';
});
}});

0 comments on commit 2511764

Please sign in to comment.