How can I manually re-enable links (not form elements) that get disabled with Rails' disable_with
feature?
The call to reenable links is slightly different than form elements. It actually binds a handler to the click event that stops anything else from happening. I was able to figure this out by investigating how the jquery-ujs library.
To reverse this effect, simply use the enableElement
method on your jQuery object:
$.rails.enableElement($('a[data-disable-with]'));
With Turbolinks, it also helps to watch for the 'page:change'
event instead of window.unload
:
$(document).on('page:change', function() {
$.rails.enableElement($('a[data-disable-with]'));
});
A solution I found here:
$(window).unload(function() {
$.rails.enableFormElements($($.rails.formSubmitSelector));
});
Rails has updated their javascript to no longer use jQuery.
You can now re-enable elements with the following (assuming you are still using jQuery):
var selectors = [Rails.linkDisableSelector, Rails.formEnableSelector].join(', ');
$(selectors).each(function() {
Rails.enableElement(this);
})
Hey its quite simple you just need to find button and do
$button = $('#someId')
$.rails.enableElement($button)
$button.removeAttr('disabled')
value
) of the button back to what it was before submission. –
Satirical Based on @DGM solution I ended up with the following code:
$.rails.enableFormElements($disabled_button);
Where:
$disabled_button
is the jQuery object for the button disabled by data-disable-with
which could be selected like this:
$disabled_button = $('[data-disable-with]');
OK I found this interesting work around (apparently the problem is only in FF) set :autocomplete => 'off' and now it works. Or one of the other answer might work as well.
You can use jQuery to remove the data-disable-with attribute that Rails adds to the button: $('#disabledbutton').removeAttr('data-disable-with');
© 2022 - 2024 — McMap. All rights reserved.
$.rails.enableFormElements
and it will re-enable it. In my case I passed the form I was submitting:$.rails.enableFormElements( $( 'div.modal form' ) )
– Satirical