fix: sync bulk request selection before submit

This commit is contained in:
Md Bayazid Bostame
2026-03-30 12:44:36 +02:00
parent bce58b3f25
commit c27ac84c06

View File

@@ -32,6 +32,7 @@
const selectAll = document.getElementById('select-all'); const selectAll = document.getElementById('select-all');
const rowChecks = Array.from(document.querySelectorAll('.row-select')); const rowChecks = Array.from(document.querySelectorAll('.row-select'));
const selectedCount = document.getElementById('selected-count'); const selectedCount = document.getElementById('selected-count');
const bulkForm = document.getElementById('bulk-delete-form');
if (!selectAll || !selectedCount || !rowChecks.length) return; if (!selectAll || !selectedCount || !rowChecks.length) return;
function updateCount() { function updateCount() {
@@ -41,10 +42,31 @@
selectAll.indeterminate = checked > 0 && checked < rowChecks.length; selectAll.indeterminate = checked > 0 && checked < rowChecks.length;
} }
function syncBulkSelection() {
if (!bulkForm) return;
bulkForm.querySelectorAll('input[type="hidden"][data-bulk-selected="1"]').forEach(function (node) {
node.remove();
});
rowChecks.forEach(function (checkbox) {
if (!checkbox.checked) return;
const hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'selected_requests';
hidden.value = checkbox.value;
hidden.setAttribute('data-bulk-selected', '1');
bulkForm.appendChild(hidden);
});
}
selectAll.addEventListener('change', function () { selectAll.addEventListener('change', function () {
rowChecks.forEach((c) => { c.checked = selectAll.checked; }); rowChecks.forEach((c) => { c.checked = selectAll.checked; });
updateCount(); updateCount();
}); });
rowChecks.forEach((c) => c.addEventListener('change', updateCount)); rowChecks.forEach((c) => c.addEventListener('change', updateCount));
if (bulkForm) {
bulkForm.addEventListener('submit', function () {
syncBulkSelection();
});
}
updateCount(); updateCount();
})(); })();