-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add loading status to submit buttons #10459
Conversation
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Adding Also, wtf is up with fomantic's CSS. The matching selector for a loading button is: .ui.loading.loading.loading.loading.loading.loading.button |
Also, I'm thinking something like below but it'd be a major refactor button.addEventListener('click', async ({target}) => {
target.classList.add('loading');
await doRequest();
target.classList.remove('loading');
}); |
I agree it's not ideal, but I wasn't sure how else to temporarily disable a button in the event the submit doesn't actually fire. |
Seems that EDIT: Adding |
Signed-off-by: jolheiser <john.olheiser@gmail.com>
Not sure how the form validation works but I guess there must be some way to query if a form is valid (there should be existing code as it's not possible to create a new repo with empty name).
I don't like $('body').on('click', 'form.ui.form button.ui.green.button').click(function (e) {
if (e.currentTarget.classList.contains('loading')) return e.preventDefault();
// check validity of form somehow
if (!valid) return e.preventDefault();
e.currentTarget.classList.add('loading');
}); This assumes every form is submitted synchronously and navigation happens on submit. I'm pretty certain there are some ajax forms that would need to remove the It uses a delegated listener so it would work for forms inserted via JS too. Note that |
Maybe it'd be possible to hook into the |
Maybe we could exclude failed form with the CSS selector |
So those |
Probably, but I think I'd rather use I think I might look into hooking the submit event. |
Codecov Report
@@ Coverage Diff @@
## master #10459 +/- ##
==========================================
+ Coverage 43.7% 43.73% +0.02%
==========================================
Files 586 585 -1
Lines 81411 82014 +603
==========================================
+ Hits 35582 35866 +284
- Misses 41428 41707 +279
- Partials 4401 4441 +40
Continue to review full report at Codecov.
|
Form submit event is probably also no good because you don't know which button was pressed (for example issue comment is two buttons). I think current approach is almost fine but maybe you can try the "is valid" API to check validity before setting loading state. The timed reset is probably unavoidable for sync form submissions. For async ones, code should be able to set it. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
$this.addClass('loading'); | ||
setTimeout(() => { | ||
$this.removeClass('loading'); | ||
}, 1000 * 5); // 5 seconds |
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.
We should enable the button only after received the HTTP response.
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 believe this only applies to "real" forms, in which case receiving a response means the page is reloading I think?
This timeout is a fallback in case it fails so the button isn't stuck perpetually loading.
Quoting myself again in case it was missed:
So what this needs is at least:
|
I will try to look at this again soon. Thanks for the tips @silverwind |
I had a thought about this the other day, perhaps rather than mess with disabling (and possibly re-enabling), would it make more sense to add a debounce to the buttons instead? |
The common debounce functions would still emit a second event at the end of the debounce duration, unless you want to delay the initial event but I don't think it's a good idea to introduce artifical latency. |
debounce would be better suited to our a label setting and notifications pages. I think a throttle/disable would be a better fit for our buttons |
A similar PR has been merged: |
conflicted with #16157, so let's close this one. |
Possible fix for #6859 and similar.
This is a "one size fits all solution" and so I'm not sure it's the best approach, open to criticism.
Perhaps it would be better to add this mechanism to individual buttons?