Skip to content

Commit

Permalink
Fix loading button with invalid form (go-gitea#20754)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and Sysoev, Vladimir committed Aug 28, 2022
1 parent 7bc38c9 commit f455968
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

Expand Down

0 comments on commit f455968

Please sign in to comment.