jquery-ujs
jquery-ujs copied to clipboard
Submit button did not get re-enabled after form submission
I have a form's submit button that utilizes Rails, jquery-ujs library, and data-disable-with attribute. When I clicked on the submit button, it disabled as it should, and submission went through successfully. However, when I clicked the Browser's back button, the button was still disabled. Looking at the raw HTML, the button had added attribute disabled="". I am assuming query-ujs should re-enable the button after form submission with enableSelector.
How could we do that? After form submission you're on a different page and the button doesn't exist anymore in the DOM.
Also, are you using Safari by any chance? You may have a look at #306 .
No, I've been using Firefox. I was thinking that on page's unload you can remove the disabled="".
Interesting idea. I've had the same problem but never came up with a solution.
I have similar problem with links too. If I am using non ajax links with disable-with attribute, when I click on them and than hit Back button, the link stays disabled.
I am using this workaround to trigger ajax:complete on page:receive turbolinks event:
$(document).on('page:receive', function() {
$('[data-disable-with]:not([data-remote])').trigger('ajax:complete');
});
As I see, currently we enableElements only on ajax links and forms
What do you think to write extend disable-with functionality to work on non ajax links ?
Just remove focus on button :
$('#button').blur();
Same problem here, and can't find a solution :-/ tried with
.complete( ->
$.rails.enableFormElements form
but it doesn't work
@JangoSteve I am also facing this issue with a reports page. The submit button actually triggers a download of a csv report and on clicking the Submit button will be disabled. Since, it is a download, it stays on that page instead of redirecting to another page, and the Submit button will remain disabled.
I solved this by adding data-remote="true" to my form, as suggested here: https://github.com/rails/jquery-ujs/wiki/Unobtrusive-scripting-support-for-jQuery#data-remote-make-links-and-forms-submit-asynchronously-with-ajax