瀏覽代碼

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

Frédéric Guillot 8 月之前
父節點
當前提交
7a25cf5037
共有 2 個文件被更改,包括 13 次插入7 次删除
  1. 12 6
      internal/ui/static/js/app.js
  2. 1 1
      internal/ui/static/js/bootstrap.js

+ 12 - 6
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;
-            }
+            });
         };
     });
 }

+ 1 - 1
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();