function validation(event) { // возвращает true/false
function removeError(input) {
let inputParent = input.closest('.form__group')
if (input.classList.contains('error')) {
inputParent.querySelector('.error-label').remove()
input.classList.remove('error')
}
}
function createError(input, text) {
let inputParent = input.closest('.form__group')
let errorParagraph = document.createElement('p')
input.classList.add('error')
errorParagraph.classList.add('error-label')
errorParagraph.textContent = text
inputParent.append(errorParagraph)
}
let result = true
let formInputs = event.target.querySelectorAll('.form__input')
formInputs.forEach(input => {
removeError(input)
if (input.value == '') {
createError(input, 'Поле не заполнено!')
result = false
}
})
return result
}