Re-enable submit buttons disabled by the :disable_with option

Updated . Posted . Visible to the public.

Submit buttons in Rails come with a useful option :disable_with which will disable the button when clicked and change its label to something like "Please wait...".

An annoying side effect of that feature is that when you use the back button to return to the form, the submit button will be greyed out and disabled.

A solution is to re-enable the submit button before leaving the page. This works in Rails 3:

$(window).unload(function() {
  $.rails.enableFormElements($($.rails.formSubmitSelector));
});
Henning Koch
Last edit
Martin Straub
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-12-07 20:39)