mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-04 20:29:47 -06:00
30 lines
752 B
JavaScript
30 lines
752 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
// Connects to data-controller="checkbox-select-all"
|
|
export default class extends Controller {
|
|
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)
|
|
console.log('toggleChildrenChecked')
|
|
} else {
|
|
this.childTargets.map(x => x.checked = false)
|
|
console.log('toggleChildrenUNChecked')
|
|
}
|
|
}
|
|
|
|
toggleParent() {
|
|
if (this.childTargets.map(x => x.checked).includes(false)) {
|
|
this.parentTarget.checked = false
|
|
} else {
|
|
this.parentTarget.checked = true
|
|
}
|
|
}
|
|
}
|