Skip to content

Commit

Permalink
Ensure newly created checkboxes are selected
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmhaig committed Oct 20, 2023
1 parent e2c3f3d commit 9486330
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/webpack/javascripts/modules/selectAll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export class SelectAll {
if (!this.$module) { return }

const selector = this.$module.dataset.selectAllClass
const collection = this.$module.dataset.collectionClass
this.collection = this.$module.dataset.collectionClass

this.selectAllBox = this.$module.querySelector(`.${selector}`)
this.selectAllBox.addEventListener('change', () => this.toggleSelection())
this.checkBoxes = document.querySelectorAll(`.${collection}`)
}

toggleSelection = () => {
this.checkBoxes.forEach((box) => { box.checked = this.selectAllBox.checked })
const checkBoxes = document.querySelectorAll(`.${this.collection}`)
checkBoxes.forEach((box) => { box.checked = this.selectAllBox.checked })
}
}

0 comments on commit 9486330

Please sign in to comment.