jquery-ujs icon indicating copy to clipboard operation
jquery-ujs copied to clipboard

Submit button did not get re-enabled after form submission

Open chase439 opened this issue 12 years ago • 9 comments
trafficstars

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.

chase439 avatar May 31 '13 05:05 chase439

How could we do that? After form submission you're on a different page and the button doesn't exist anymore in the DOM.

JangoSteve avatar May 31 '13 11:05 JangoSteve

Also, are you using Safari by any chance? You may have a look at #306 .

JangoSteve avatar May 31 '13 11:05 JangoSteve

No, I've been using Firefox. I was thinking that on page's unload you can remove the disabled="".

chase439 avatar May 31 '13 15:05 chase439

Interesting idea. I've had the same problem but never came up with a solution.

bcm avatar May 31 '13 18:05 bcm

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 ?

duleorlovic avatar Jul 31 '14 18:07 duleorlovic

Just remove focus on button : $('#button').blur();

eldiyar7 avatar Mar 09 '17 20:03 eldiyar7

Same problem here, and can't find a solution :-/ tried with

.complete( ->
  $.rails.enableFormElements form

but it doesn't work

mdesantis avatar Mar 10 '17 10:03 mdesantis

@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.

princejoseph avatar May 25 '17 11:05 princejoseph

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

bavedarnow avatar Aug 21 '17 15:08 bavedarnow