[英]Re-enable links disabled with disable_with
如何手动重新启用使用disable_with
功能禁用的链接(而不是表单元素)?
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. 它实际上将处理程序绑定到click事件,以阻止其他任何事情发生。 I was able to figure this out by investigating how the jquery-ujs library . 我能够通过调查jquery-ujs库来解决这个问题。
To reverse this effect, simply use the enableElement
method on your jQuery object: 要反转此效果,只需在jQuery对象上使用enableElement
方法:
$.rails.enableElement($('a[data-disable-with]'));
With Turbolinks, it also helps to watch for the 'page:change'
event instead of window.unload
: 使用Turbolinks,它还有助于监视'page:change'
事件而不是window.unload
:
$(document).on('page:change', function() {
$.rails.enableElement($('a[data-disable-with]'));
});
Rails has updated their javascript to no longer use jQuery. Rails更新了他们的javascript,不再使用jQuery。
You can now re-enable elements with the following (assuming you are still using jQuery): 您现在可以使用以下内容重新启用元素(假设您仍在使用jQuery):
var selectors = [Rails.linkDisableSelector, Rails.formEnableSelector].join(', ');
$(selectors).each(function() {
Rails.enableElement(this);
})
Based on @DGM solution I ended up with the following code: 基于@DGM解决方案,我最终得到以下代码:
$.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
的按钮的jQuery对象,可以像这样选择:
$disabled_button = $('[data-disable-with]');
您可以使用jQuery删除Rails添加到按钮的data-disable-with属性:$('#dailedbutton')。removeAttr('data-disable-with');
OK I found this interesting work around (apparently the problem is only in FF) set :autocomplete => 'off' and now it works. 好的我发现这个有趣的工作(显然问题只在FF中)设置:autocomplete =>'off',现在它可以工作了。 Or one of the other answer might work as well. 或者其中一个答案可能也有效。
ref: https://github.com/rails/jquery-ujs/issues/357 参考: https : //github.com/rails/jquery-ujs/issues/357
Hey its quite simple you just need to find button and do 嘿,它很简单你只需要找到按钮并做
$button = $('#someId')
$.rails.enableElement($button)
$button.removeAttr('disabled')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.