diff options
author | silverwind <me@silverwind.io> | 2022-08-11 05:54:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 11:54:34 +0800 |
commit | 57f1ea03661945f75cf2ff11120eb07447692c99 (patch) | |
tree | ddaf95c4f6d9b3845ef8afe3145d5106127e3a93 | |
parent | 54d9816502cb5709cfd7df9b43fb7b02c5c88033 (diff) | |
download | gitea-57f1ea03661945f75cf2ff11120eb07447692c99.tar.gz gitea-57f1ea03661945f75cf2ff11120eb07447692c99.zip |
Fix loading button with invalid form (#20754)
Previously, if a invalid form was submitted (for example issue with no
title), the form could not be re-submitted again because the button
would not stay stuck in loading state. Fix that by hooking the 'submit'
event instead which triggers only when the form is valid.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | web_src/js/features/common-global.js | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 1776f6577d..259e409add 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -142,16 +142,12 @@ export function initGlobalCommon() { } }); - // loading-button this logic used to prevent push one form more than one time - $(document).on('click', '.button.loading-button', function (e) { - const $btn = $(this); - - if ($btn.hasClass('loading')) { - e.preventDefault(); - return false; - } - - $btn.addClass('loading disabled'); + // prevent multiple form submissions on forms containing .loading-button + document.addEventListener('submit', (e) => { + const btn = e.target.querySelector('.loading-button'); + if (!btn) return; + if (btn.classList.contains('loading')) return e.preventDefault(); + btn.classList.add('loading'); }); } |