mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-02-13 01:03:59 -05:00
Added Checkbox Controller javascript
This commit is contained in:
23
assets/javascripts/checkbox_controller.js
Normal file
23
assets/javascripts/checkbox_controller.js
Normal 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;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user