Skip to content

Commit

Permalink
DOMツリー読み込み完了時にも、submitボタンの有効無効を更新するように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
naokinaokiboo committed Feb 28, 2024
1 parent 9e84b47 commit 0437510
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/javascript/agreements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ document.addEventListener('DOMContentLoaded', () => {
)
const submit = document.querySelector('.js-agreements-submit')

checkboxes.forEach((element) => {
element.addEventListener('click', () => {
const isSubmit = checkboxes.every((element) => element.checked)
const updateSubmitButtonStateFromCheckbox = () => {
const isSubmit = checkboxes.every((element) => element.checked)
if (isSubmit) {
submit.classList.remove('is-disabled')
} else {
submit.classList.add('is-disabled')
}
}

if (isSubmit) {
submit.classList.remove('is-disabled')
} else {
submit.classList.add('is-disabled')
}
if (checkboxes.length) {
checkboxes.forEach((element) => {
element.addEventListener('click', updateSubmitButtonStateFromCheckbox)
})
})

updateSubmitButtonStateFromCheckbox()
}
})

0 comments on commit 0437510

Please sign in to comment.