Files
openfoodnetwork/app/webpacker/controllers/select_all_controller.js
Cillian O'Ruanaidh 8e47949260 Check 'Select all' checkboxes on page load if all its checkboxes are checked
This means the code to set the initial value in the view template isn't needed.
2022-09-30 13:13:39 +01:00

20 lines
407 B
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["all", "checkbox"];
connect() {
this.toggleCheckbox()
}
toggleAll() {
this.checkboxTargets.forEach(checkbox => {
checkbox.checked = this.allTarget.checked;
});
}
toggleCheckbox() {
this.allTarget.checked = this.checkboxTargets.every(checkbox => checkbox.checked);
}
}