2024-08-05 11:07:03 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
2024-08-06 12:11:27 +00:00
|
|
|
const form = document.querySelector('form');
|
|
|
|
const submitButton = form.querySelector('button[type="submit"]');
|
|
|
|
const errorElement = document.getElementById('error');
|
|
|
|
|
|
|
|
form.addEventListener('keydown', function(event) {
|
2024-08-05 11:07:03 +00:00
|
|
|
const activeElement = document.activeElement;
|
2024-08-06 12:11:27 +00:00
|
|
|
const formElements = Array.from(form.elements);
|
|
|
|
const currentIndex = formElements.indexOf(activeElement);
|
|
|
|
|
|
|
|
if (activeElement.tagName === 'INPUT') {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
event.preventDefault();
|
|
|
|
if (currentIndex === formElements.length - 1) {
|
|
|
|
submitButton.focus();
|
|
|
|
} else if (currentIndex !== -1 && formElements[currentIndex + 1]) {
|
|
|
|
formElements[currentIndex + 1].focus();
|
|
|
|
}
|
2024-08-05 11:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-06 12:11:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
submitButton.addEventListener('focus', function() {
|
|
|
|
submitButton.classList.add('focus-visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
submitButton.addEventListener('blur', function() {
|
|
|
|
submitButton.classList.remove('focus-visible');
|
|
|
|
});
|
|
|
|
|
|
|
|
form.addEventListener('submit', function(event) {
|
|
|
|
if (!validateForm()) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function validateForm() {
|
|
|
|
const username = document.getElementById('username').value.trim();
|
|
|
|
const login = document.getElementById('login').value.trim();
|
|
|
|
const password = document.getElementById('password').value.trim();
|
|
|
|
|
|
|
|
if (username === '' || login === '' || password === '') {
|
|
|
|
errorElement.textContent = 'Пожалуйста, заполните все поля';
|
|
|
|
errorElement.style.display = 'block';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2024-08-05 11:07:03 +00:00
|
|
|
}
|
|
|
|
});
|