diff --git a/app/javascript/agreements.js b/app/javascript/agreements.js index 7b465e116c3..ae92d93eb31 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() + } }) diff --git a/app/views/users/_form.html.slim b/app/views/users/_form.html.slim index e43b183f0fc..ae85da3fc5b 100644 --- a/app/views/users/_form.html.slim +++ b/app/views/users/_form.html.slim @@ -140,7 +140,7 @@ ul.block-checks.is-1-item li.block-checks__item .a-block-check.is-checkbox - = check_box_tag :coc, 1, false, class: 'a-toggle-checkbox js-agreements-checkbox' + = check_box_tag :coc, 1, params[:coc], class: 'a-toggle-checkbox js-agreements-checkbox' label.a-block-check__label.is-ta-left(for='coc') | アンチハラスメントポリシーに同意 .a-form-help @@ -149,7 +149,7 @@ ul.block-checks.is-1-item li.block-checks__item .a-block-check.is-checkbox - = check_box_tag :tos, 2, false, class: 'a-toggle-checkbox js-agreements-checkbox' + = check_box_tag :tos, 2, params[:tos], class: 'a-toggle-checkbox js-agreements-checkbox' label.a-block-check__label.is-ta-left(for='tos') | 利用規約に同意 .a-form-help