Validate all modal fields at once with per-field highlighting
This commit is contained in:
@@ -1516,3 +1516,10 @@ button {
|
|||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Invalid field highlight in access modal */
|
||||||
|
.access-field input.am-invalid {
|
||||||
|
border-color: rgba(220, 70, 70, 0.7) !important;
|
||||||
|
box-shadow: 0 0 0 3px rgba(220, 70, 70, 0.15) !important;
|
||||||
|
background: rgba(220, 70, 70, 0.05) !important;
|
||||||
|
}
|
||||||
|
|||||||
+27
-13
@@ -140,6 +140,7 @@
|
|||||||
overlay.style.display = 'none';
|
overlay.style.display = 'none';
|
||||||
document.body.style.overflow = '';
|
document.body.style.overflow = '';
|
||||||
errEl.style.display = 'none';
|
errEl.style.display = 'none';
|
||||||
|
document.querySelectorAll('.am-invalid').forEach(el => el.classList.remove('am-invalid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadProducts() {
|
async function loadProducts() {
|
||||||
@@ -177,23 +178,31 @@
|
|||||||
|
|
||||||
const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
const phoneRe = /^[\+\d][\d\s\-\(\)]{6,18}$/;
|
const phoneRe = /^[\+\d][\d\s\-\(\)]{6,18}$/;
|
||||||
if (!name || !company || !email || !phone) {
|
|
||||||
errEl.textContent = 'Пожалуйста, заполните все обязательные поля';
|
const fields = [
|
||||||
errEl.style.display = 'block';
|
{ el: document.getElementById('am-name'), val: name, check: () => !!name, msg: 'Введите имя и фамилию' },
|
||||||
return;
|
{ el: document.getElementById('am-company'), val: company, check: () => !!company, msg: 'Введите название компании' },
|
||||||
}
|
{ el: document.getElementById('am-email'), val: email, check: () => emailRe.test(email), msg: 'Введите корректный email' },
|
||||||
if (!emailRe.test(email)) {
|
{ el: document.getElementById('am-phone'), val: phone, check: () => phoneRe.test(phone), msg: 'Введите корректный номер телефона' },
|
||||||
errEl.textContent = 'Введите корректный email';
|
];
|
||||||
errEl.style.display = 'block';
|
|
||||||
return;
|
const errors = [];
|
||||||
}
|
fields.forEach(f => {
|
||||||
if (!phoneRe.test(phone)) {
|
if (!f.check()) {
|
||||||
errEl.textContent = 'Введите корректный номер телефона';
|
f.el.classList.add('am-invalid');
|
||||||
|
errors.push(f.msg);
|
||||||
|
} else {
|
||||||
|
f.el.classList.remove('am-invalid');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
errEl.textContent = errors.join(' • ');
|
||||||
errEl.style.display = 'block';
|
errEl.style.display = 'block';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
btnSubmit.disabled = true;
|
btnSubmit.disabled = true;
|
||||||
btnSubmit.textContent = 'Отправка...';
|
btnSubmit.textContent = 'Отправка...';
|
||||||
errEl.style.display = 'none';
|
errEl.style.display = 'none';
|
||||||
|
|
||||||
@@ -217,6 +226,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear invalid highlight on input
|
||||||
|
document.querySelectorAll('#am-name,#am-company,#am-email,#am-phone').forEach(el => {
|
||||||
|
el.addEventListener('input', () => el.classList.remove('am-invalid'));
|
||||||
|
});
|
||||||
|
|
||||||
// Wire up request-access button
|
// Wire up request-access button
|
||||||
document.querySelectorAll('.login-request-btn, [data-open-access-modal]').forEach(el => {
|
document.querySelectorAll('.login-request-btn, [data-open-access-modal]').forEach(el => {
|
||||||
el.addEventListener('click', function(e) {
|
el.addEventListener('click', function(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user