Skip to content

Commit 57f1ea0

Browse files
silverwindlunny
andauthored
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 <[email protected]>
1 parent 54d9816 commit 57f1ea0

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

web_src/js/features/common-global.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,12 @@ export function initGlobalCommon() {
142142
}
143143
});
144144

145-
// loading-button this logic used to prevent push one form more than one time
146-
$(document).on('click', '.button.loading-button', function (e) {
147-
const $btn = $(this);
148-
149-
if ($btn.hasClass('loading')) {
150-
e.preventDefault();
151-
return false;
152-
}
153-
154-
$btn.addClass('loading disabled');
145+
// prevent multiple form submissions on forms containing .loading-button
146+
document.addEventListener('submit', (e) => {
147+
const btn = e.target.querySelector('.loading-button');
148+
if (!btn) return;
149+
if (btn.classList.contains('loading')) return e.preventDefault();
150+
btn.classList.add('loading');
155151
});
156152
}
157153

0 commit comments

Comments
 (0)