1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

fix(js): handle multiple buttons in a single form when showing loading state

This commit is contained in:
Frédéric Guillot 2025-08-01 20:50:00 -07:00
parent 1ec90e34f5
commit 7a25cf5037
2 changed files with 13 additions and 7 deletions

View file

@ -140,15 +140,21 @@ function onClickMainMenuListItem(event) {
} }
} }
// Change the button label when the page is loading. /**
function handleSubmitButtons() { * This function changes the button label to the loading state and disables the button.
*
* @returns {void}
*/
function disableSubmitButtonsOnFormSubmit() {
document.querySelectorAll("form").forEach((element) => { document.querySelectorAll("form").forEach((element) => {
element.onsubmit = () => { element.onsubmit = () => {
const button = element.querySelector("button"); const buttons = element.querySelectorAll("button[type=submit]");
if (button) { buttons.forEach((button) => {
button.textContent = button.dataset.labelLoading; if (button.dataset.labelLoading) {
button.textContent = button.dataset.labelLoading;
}
button.disabled = true; button.disabled = true;
} });
}; };
}); });
} }

View file

@ -1,5 +1,5 @@
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
handleSubmitButtons(); disableSubmitButtonsOnFormSubmit();
if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) { if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) {
const keyboardHandler = new KeyboardHandler(); const keyboardHandler = new KeyboardHandler();