Skip to content

data-disable-with keeps the button disabled when the user hit browser's back button #357

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

Closed
sobrinho opened this issue Feb 25, 2014 · 13 comments · Fixed by #385
Closed

data-disable-with keeps the button disabled when the user hit browser's back button #357

sobrinho opened this issue Feb 25, 2014 · 13 comments · Fixed by #385

Comments

@sobrinho
Copy link
Contributor

If the user hits the browser's back button after submitting a form, the submit button is kept disabled, we must refresh the page to the restore the button state.

I found this workaround which seems to be working: [I lost the link]

It happens on Safari and Firefox, Chrome is fine.

Not sure about other browsers, I do not have any other here :)

@pekeler
Copy link
Contributor

pekeler commented Mar 3, 2014

I can't read that workaround.
If you serve up your pages such they aren't cached by the browser, it'll solve this problem.
http://www.fordevs.com/2011/10/how-to-prevent-browser-from-caching-a-page-in-rails.html

@lacco
Copy link

lacco commented Aug 6, 2014

@sobrinho : Could you give more details to your workaround? It seems that I stumpled upon this same issue, although it occurs to me when reloading the page instead of hitting the back button.

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 6, 2014

I posted the wrong link.

The workaround I've seen is to set autocomplete="off" on submit buttons.

@lacco
Copy link

lacco commented Aug 6, 2014

Wow, you are totally right, using something like <input type="submit" autocomplete="off" ... /> fixes the issue. It seems to be some Firefox quirk, e.g. the same issue also exists in bootstrap: twbs/bootstrap#793 . I suggest closing the issue since this is nothing that jquery-ujs should fix?

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 6, 2014

I think it should be fixed by jquery-ujs, we just need to set autocomplete attribute automatically on data-disable-with inputs, something like that:

<input type="submit" data-disable-with="Loading...">

Automatically goes to:

<input type="submit" data-disable-with="Loading..." autocomplete="off">

If it is okay, I can make a pull request :)

@lucasmazza
Copy link
Contributor

I'm not comfortable with pushing hacks like this with the JS code. Maybe there is somewhere in the Rails docs/guides that we add a note about this similar to what was done in Bootstrap? /cc @rafaelfranca

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 7, 2014

Yeah, I'm not comfortable either but considering the data-disable-with is broken, you should fix it yourself vs. data-disable-with just works and you should not care about anything, I prefer the later.

This hack is harmless and since it will not cause any side-effect, I'm okay with it.

@rafaelfranca
Copy link
Member

Browsers... ¯_(ツ)_/¯

What is broken here are the browsers. The data-disable-with feature is working fine for browsers that do not do sourcery and only work with autocomplete=off (that by the way, is completely no sense).

I don't want to add this hack to jquery-ujs too but I agree it is harmless and may save some time of people. It may be worth to add even if it is browsers fault.

@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 7, 2014

So, can I make a pull request? 😻

@rafaelfranca
Copy link
Member

Yes. It will help to decide if it is worth or not.

sobrinho added a commit to sobrinho/jquery-ujs that referenced this issue Aug 7, 2014
Firefox has a weird behavior where when you hit the back button it keeps
the submit buttons and links on disabled state which even reloading the
page do not re-enables them.

Using the pageshow event, which is triggered every time a page loads, we
can keep the rails-ujs behavior consistent with all other browsers.

See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching

[Fixes rails#357]
@sobrinho
Copy link
Contributor Author

sobrinho commented Aug 7, 2014

See #385

sobrinho added a commit to sobrinho/jquery-ujs that referenced this issue Aug 25, 2014
Firefox has a weird behavior where when you hit the back button it keeps
the submit buttons and links on disabled state which even reloading the
page do not re-enables them.

Using the pageshow event, which is triggered every time a page loads, we
can keep the rails-ujs behavior consistent with all other browsers.

See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching

[Fixes rails#357]
@rdp
Copy link

rdp commented Sep 5, 2014

I just ran into this myself, this might be nice to ensure cross browser similar behavior...

@coderdave
Copy link

This is an old issue, but this is still occurring for me in, even in v4.1.1. The only difference is that it's not an input, it's just a regular link "button":

<%= link_to "<i class='fa fa-plus fa-inverse'></i>".html_safe, new_appointment_path,
    class: "btn btn-success new pull-right", data: { disable_with: "<i class='fa fa-spinner fa-spin'></i>" },
    id: "new_appointment_button", title: "New Appointment" %>

On first click, it spins, but when you hit the back button in Chrome for example, it stays spinning. Maybe something to do with turbolinks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants