Added Checkbox Controller javascript

This commit is contained in:
2026-01-19 19:34:59 -05:00
parent bcdd515cf1
commit 5649ba05cd
2 changed files with 27 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
document.addEventListener("turbo:load", () => {
const selectAllBox = document.getElementById("select-all-batches");
const checkboxes = document.querySelectorAll(".item-checkbox");
if (selectAllBox) {
selectAllBox.addEventListener("change", function() {
checkboxes.forEach((checkbox) => {
checkbox.checked = this.checked;
});
});
// Optional: Uncheck "Select All" if an individual box is unchecked
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("change", () => {
if (!checkbox.checked) {
selectAllBox.checked = false;
} else if (Array.from(checkboxes).every(c => c.checked)) {
selectAllBox.checked = true;
}
});
});
}
});