From ed8bc818f4c6b21d2365cc770d4faa99a56f7d1f Mon Sep 17 00:00:00 2001 From: naokinaokiboo Date: Tue, 27 Feb 2024 19:12:12 +0900 Subject: [PATCH] =?UTF-8?q?DOM=E3=83=84=E3=83=AA=E3=83=BC=E8=AA=AD?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF=E5=AE=8C=E4=BA=86=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=82=82=E3=80=81submit=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=AE?= =?UTF-8?q?=E6=9C=89=E5=8A=B9=E7=84=A1=E5=8A=B9=E3=82=92=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/agreements.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/javascript/agreements.js b/app/javascript/agreements.js index 7b465e116c3..9d9d5e7b7ba 100644 --- a/app/javascript/agreements.js +++ b/app/javascript/agreements.js @@ -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() + } })