-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent double click new issue/pull/comment button #16157
Changes from all commits
6adb632
f68a50f
b12a87e
be492c2
bd21494
27cf13e
cf4bef2
921dad9
da22521
9fd3b09
acd8874
9b7bebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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'); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks semantic ui has handled it, just add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what if it is not a Fomantic UI button? For example, what if some one writes a form without If you require the developers to use your code in Fomantic UI context, you should change the selector to |
||||||||
}); | ||||||||
} | ||||||||
|
||||||||
export function initGlobalDropzone() { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need capture instead of bubble here. Otherwise the event handler on the button would be executed first (for example: ajax, IIRC some form buttons are doing ajax requests)
https://stackoverflow.com/questions/4616694/what-is-event-bubbling-and-capturing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, what I mean is:
If we are trying to introduce a general method, should the all cases be considered together? Will this mechanism be used for ajax buttons in future?
If this mechanism is for traditional forms (non-ajax) only, these CSS names are too broad, it will be mis-used by ajax buttons in future.
If this mechanism is for both traditional forms and ajax requests, it could be fine tuned some more.
update: I would suggest to use
form-once-submit
as the CSS name for these form-only buttons.In future, we can have
ajax-once-request
CSS class for ajax buttons (if necessary), or ajax buttons should handle the repeated clicks by themselves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be generic for all use cases where technically possible and needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either is fine to me:
form
buttons, and get this PR merged.How do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about limit it by this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loading-button
is not a proper name ......If you are reading some code, when you see a button called
loading-button
, you might think it is a button which is loading something. BUT, the purpose of the class is to make the button can only submit the form once.I would suggest to use a clear name to reduce misunderstanding.