diff options
Diffstat (limited to 'p/scripts')
| -rw-r--r-- | p/scripts/extra.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/p/scripts/extra.js b/p/scripts/extra.js index 48f50325b..476970c3b 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -36,8 +36,8 @@ function init_crypto_forms() { crypto_form.onsubmit = function (e) { let challenge = crypto_form.querySelector('#challenge'); if (!challenge) { - crypto_form.querySelectorAll('[data-challenge-if-not-empty] input[type="password"]').forEach(el => { - if (el.value !== '' && !challenge) { + crypto_form.querySelectorAll('details[data-challenge-if-open]').forEach(el => { + if (el.open && !challenge) { crypto_form.insertAdjacentHTML('beforeend', '<input type="hidden" id="challenge" name="challenge" />'); challenge = crypto_form.querySelector('#challenge'); } @@ -485,6 +485,25 @@ function init_configuration_alert() { }; } +function init_details_attributes() { + function toggleRequired(details) { + details.querySelectorAll('[data-required-if-open]').forEach(el => { + if (details.open) { + el.setAttribute('required', 'required'); + } else { + el.removeAttribute('required'); + } + }); + } + + document.querySelectorAll('details').forEach(details => { + details.addEventListener('toggle', () => { + toggleRequired(details); + }); + toggleRequired(details); + }); +} + function init_extra_afterDOM() { if (!window.context) { if (window.console) { @@ -504,6 +523,7 @@ function init_extra_afterDOM() { init_configuration_alert(); init_2stateButton(); init_update_feed(); + init_details_attributes(); data_auto_leave_validation(document.body); |
