2025-02-15 10:48:03 -05:00
|
|
|
import BaseController from "./base_controller"
|
2024-05-23 14:12:23 -04:00
|
|
|
|
|
|
|
|
// Connects to data-controller="checkbox-select-all"
|
2025-02-15 10:48:03 -05:00
|
|
|
export default class extends BaseController {
|
2024-05-23 14:12:23 -04:00
|
|
|
static targets = ["parent", "child"]
|
|
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
|
this.parentTarget.checked = false
|
|
|
|
|
this.childTargets.map(x => x.checked = false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleChildren() {
|
|
|
|
|
if (this.parentTarget.checked) {
|
|
|
|
|
this.childTargets.map(x => x.checked = true)
|
|
|
|
|
} else {
|
|
|
|
|
this.childTargets.map(x => x.checked = false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleParent() {
|
|
|
|
|
if (this.childTargets.map(x => x.checked).includes(false)) {
|
|
|
|
|
this.parentTarget.checked = false
|
|
|
|
|
} else {
|
|
|
|
|
this.parentTarget.checked = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|