form: add Select All checkbox to products list in access request form
This commit is contained in:
@@ -139,7 +139,13 @@
|
||||
<input id="am-manager" type="text" placeholder="Если известно — укажите имя" />
|
||||
</div>
|
||||
<div class="access-field">
|
||||
<label>Интересующие продукты</label>
|
||||
<label style="display:flex;align-items:center;justify-content:space-between">
|
||||
Интересующие продукты
|
||||
<label id="am-select-all-wrap" style="display:none;font-weight:400;font-size:13px;cursor:pointer;gap:6px;align-items:center">
|
||||
<input type="checkbox" id="am-select-all" style="cursor:pointer" />
|
||||
<span>Выбрать все</span>
|
||||
</label>
|
||||
</label>
|
||||
<div id="am-products" class="access-products-wrap">
|
||||
<div class="access-products-loading">Загрузка...</div>
|
||||
</div>
|
||||
@@ -186,6 +192,7 @@
|
||||
} else {
|
||||
['am-name','am-company','am-email','am-phone','am-manager'].forEach(function(id){ var el=document.getElementById(id); if(el){el.value='';el.classList.remove('am-invalid');} });
|
||||
document.querySelectorAll('#am-products input[type=checkbox]').forEach(function(cb){ cb.checked=false; });
|
||||
var saBox = document.getElementById('am-select-all'); if (saBox) saBox.checked = false;
|
||||
var err=document.getElementById('am-error'); if(err) err.style.display='none';
|
||||
var btn=document.getElementById('am-submit'); if(btn){btn.disabled=false;btn.textContent='Запросить доступ';}
|
||||
}
|
||||
@@ -225,6 +232,21 @@
|
||||
wrap.appendChild(group);
|
||||
}
|
||||
productsLoaded = true;
|
||||
// Show "select all" checkbox
|
||||
const saWrap = document.getElementById('am-select-all-wrap');
|
||||
if (saWrap) saWrap.style.display = 'flex';
|
||||
const saBox = document.getElementById('am-select-all');
|
||||
if (saBox) {
|
||||
saBox.addEventListener('change', function() {
|
||||
document.querySelectorAll('#am-products input[type=checkbox]').forEach(function(cb){ cb.checked = saBox.checked; });
|
||||
});
|
||||
// Keep "select all" in sync when individual boxes change
|
||||
wrap.addEventListener('change', function(e) {
|
||||
if (e.target === saBox) return;
|
||||
const all = [...document.querySelectorAll('#am-products input[type=checkbox]')];
|
||||
saBox.checked = all.length > 0 && all.every(function(cb){ return cb.checked; });
|
||||
});
|
||||
}
|
||||
} catch(e) {
|
||||
wrap.innerHTML = '<div class="access-products-loading">Не удалось загрузить список</div>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user