From 672e5a752db8dd732ede058f97acf5336b651afb Mon Sep 17 00:00:00 2001
From: a1012112796 <1012112796@qq.com>
Date: Sat, 7 May 2022 20:24:02 +0800
Subject: [PATCH] prevent double click new issue/pull/comment button (#16157)
* prevent double click new issue/pull/comment button
when network is not good, these button maybe
double clicked, then more than one same issues
pulls or comments will be created. this pull
request will fix this bug.
Signed-off-by: a1012112796 <1012112796@qq.com>
---
templates/repo/issue/new_form.tmpl | 2 +-
templates/repo/issue/view_content.tmpl | 4 ++--
web_src/js/features/common-global.js | 12 ++++++++++++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl
index 9a4548643..9e6a69f71 100644
--- a/templates/repo/issue/new_form.tmpl
+++ b/templates/repo/issue/new_form.tmpl
@@ -20,7 +20,7 @@
{{template "repo/issue/comment_tab" .}}
-
{{end}}
{{end}}
-
+
{{.i18n.Tr "repo.issues.create_comment"}}
@@ -172,7 +172,7 @@
{{end}}
{{end}}
-
+
{{.i18n.Tr "repo.issues.create_comment"}}
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js
index dda803ae8..eb21a4bb9 100644
--- a/web_src/js/features/common-global.js
+++ b/web_src/js/features/common-global.js
@@ -142,6 +142,18 @@ export function initGlobalCommon() {
window.location = href;
}
});
+
+ // loading-button this logic used to prevent push one form more than one time
+ $(document).on('click', '.button.loading-button', function (e) {
+ const $btn = $(this);
+
+ if ($btn.hasClass('loading')) {
+ e.preventDefault();
+ return false;
+ }
+
+ $btn.addClass('loading disabled');
+ });
}
export function initGlobalDropzone() {