Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-enable links disabled with disable_with

How can I manually re-enable links (not form elements) that get disabled with Rails' disable_with feature?

like image 641
bevanb Avatar asked Jun 25 '13 10:06

bevanb


1 Answers

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]'));
});
like image 90
Matthew Avatar answered Sep 28 '22 22:09

Matthew