Skip to content

Commit d19c2c9

Browse files
authored
Fix loading button with invalid form (#20754) (#20759)
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.
1 parent 59228d8 commit d19c2c9

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
@@ -164,16 +164,12 @@ export function initGlobalCommon() {
164164
}
165165
});
166166

167-
// loading-button this logic used to prevent push one form more than one time
168-
$(document).on('click', '.button.loading-button', function (e) {
169-
const $btn = $(this);
170-
171-
if ($btn.hasClass('loading')) {
172-
e.preventDefault();
173-
return false;
174-
}
175-
176-
$btn.addClass('loading disabled');
167+
// prevent multiple form submissions on forms containing .loading-button
168+
document.addEventListener('submit', (e) => {
169+
const btn = e.target.querySelector('.loading-button');
170+
if (!btn) return;
171+
if (btn.classList.contains('loading')) return e.preventDefault();
172+
btn.classList.add('loading');
177173
});
178174
}
179175

0 commit comments

Comments
 (0)