Skip to content
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

Rails 3 disable with remote form button immediately re-enabled #5

Open
nielsm opened this issue Apr 8, 2011 · 1 comment
Open

Rails 3 disable with remote form button immediately re-enabled #5

nielsm opened this issue Apr 8, 2011 · 1 comment

Comments

@nielsm
Copy link

nielsm commented Apr 8, 2011

Taken from:https://rails.lighthouseapp.com/projects/8994/tickets/5714-rails3-disable_with-remote-form-button-immediately-gets-re-enabled

When submitting a remote form with a "disable_with" option, the reasonable expectation is that the button will be re-enabled after the ajax response. Instead, the button is immediately re-enabled after the request is made but before the response is received. The problem is that the re-enabling code in rails.js (lines 167-174) is fired on ajax:after:

document.on("ajax:after", "form", function(event, element) {
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
inputs.each(function(input) {
input.value = input.readAttribute('data-original-value');
input.removeAttribute('data-original-value');
input.disabled = false;
});
});
If changed to be ajax:complete (line 167):

document.on("ajax:complete", "form", function(event, element) {
//original code here
}
The code works as expected: the button is disabled until the ajax response is received.

@tobioboye
Copy link

I get the exact same behaviour. I have had to rename the "ajax:after" event handler to an "ajax:complete" one to get my button to be disabled. Is this issue being fixed any time soon or should we settle with renaming the event handler?

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

No branches or pull requests

2 participants