From 7a25cf503704bf252c316fa4cfa9bd5227f4727e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Fri, 1 Aug 2025 20:50:00 -0700 Subject: [PATCH] fix(js): handle multiple buttons in a single form when showing loading state --- internal/ui/static/js/app.js | 18 ++++++++++++------ internal/ui/static/js/bootstrap.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/ui/static/js/app.js b/internal/ui/static/js/app.js index 4c8eb7c8..73f99983 100644 --- a/internal/ui/static/js/app.js +++ b/internal/ui/static/js/app.js @@ -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) => { element.onsubmit = () => { - const button = element.querySelector("button"); - if (button) { - button.textContent = button.dataset.labelLoading; + const buttons = element.querySelectorAll("button[type=submit]"); + buttons.forEach((button) => { + if (button.dataset.labelLoading) { + button.textContent = button.dataset.labelLoading; + } button.disabled = true; - } + }); }; }); } diff --git a/internal/ui/static/js/bootstrap.js b/internal/ui/static/js/bootstrap.js index 82b08d7d..0f93b6e5 100644 --- a/internal/ui/static/js/bootstrap.js +++ b/internal/ui/static/js/bootstrap.js @@ -1,5 +1,5 @@ document.addEventListener("DOMContentLoaded", () => { - handleSubmitButtons(); + disableSubmitButtonsOnFormSubmit(); if (!document.querySelector("body[data-disable-keyboard-shortcuts=true]")) { const keyboardHandler = new KeyboardHandler();