Skip to content

Commit 7a25cf5

Browse files
committed
fix(js): handle multiple buttons in a single form when showing loading state
1 parent 1ec90e3 commit 7a25cf5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

internal/ui/static/js/app.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,21 @@ function onClickMainMenuListItem(event) {
140140
}
141141
}
142142

143-
// Change the button label when the page is loading.
144-
function handleSubmitButtons() {
143+
/**
144+
* This function changes the button label to the loading state and disables the button.
145+
*
146+
* @returns {void}
147+
*/
148+
function disableSubmitButtonsOnFormSubmit() {
145149
document.querySelectorAll("form").forEach((element) => {
146150
element.onsubmit = () => {
147-
const button = element.querySelector("button");
148-
if (button) {
149-
button.textContent = button.dataset.labelLoading;
151+
const buttons = element.querySelectorAll("button[type=submit]");
152+
buttons.forEach((button) => {
153+
if (button.dataset.labelLoading) {
154+
button.textContent = button.dataset.labelLoading;
155+
}
150156
button.disabled = true;
151-
}
157+
});
152158
};
153159
});
154160
}

internal/ui/static/js/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
document.addEventListener("DOMContentLoaded", () => {
2-
handleSubmitButtons();
2+
disableSubmitButtonsOnFormSubmit();
33

44
if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) {
55
const keyboardHandler = new KeyboardHandler();

0 commit comments

Comments
 (0)