Skip to content

Commit

Permalink
prevent double click new issue/pull/comment button (#16157)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
a1012112796 committed May 7, 2022
1 parent 0eac09e commit 672e5a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
{{template "repo/issue/comment_tab" .}}
<div class="text right">
<button class="ui green button" tabindex="6">
<button class="ui green button loading-button" tabindex="6">
{{if .PageIsComparePull}}
{{.i18n.Tr "repo.pulls.create"}}
{{else}}
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</div>
{{end}}
{{end}}
<button class="ui green button" tabindex="5">
<button class="ui green button loading-button" tabindex="5">
{{.i18n.Tr "repo.issues.create_comment"}}
</button>
</div>
Expand Down Expand Up @@ -172,7 +172,7 @@
</div>
{{end}}
{{end}}
<button class="ui green button" tabindex="5">
<button class="ui green button loading-button" tabindex="5">
{{.i18n.Tr "repo.issues.create_comment"}}
</button>
</div>
Expand Down
12 changes: 12 additions & 0 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 672e5a7

Please sign in to comment.