在这下面的代码:disable_with没有在轨道3工作,但它是在轨工作完美2.2的Rails 3:在提交按钮:disable_with不工作
什么是错误的代码?
<%= submit_tag "Save", :class => "buttons",
:disable_with => "Processing",
:id => 'save_btn' %>
在这下面的代码:disable_with没有在轨道3工作,但它是在轨工作完美2.2的Rails 3:在提交按钮:disable_with不工作
什么是错误的代码?
<%= submit_tag "Save", :class => "buttons",
:disable_with => "Processing",
:id => 'save_btn' %>
从版本3.2.5开始,您不应该使用:disable_with。
<%= submit_tag "Save", 'data-disable-with' => "Processing", :class => "buttons", :id => 'save_btn' %>
或
<%= submit_tag "Save", data: { disable_with: "Processing" }, :class => "buttons", :id => 'save_btn' %>
我正在使用rails 3.0。上面的两个都不行.. OMG!真的很烦! –
对于3.0,你的语法已经死了。唯一可能的其他事情是与该类或id相关联的其他一些JavaScript干扰该操作。 –
我注意到,在我的宝石文件'jquery-rails'被赞扬:( –
检查您原始的HTML如下:
你可以阅读更多的https://github.com/rails/jquery-ujs。不同导轨版本的不同安装。
我在Safari 8.0.6和最新的rails-ujs上有类似的问题。这里是我解决这个问题的办法:
%button{ class: 'btn btn-action js-submit', data: { method: :put, 'href' => '...', disable_with: "<i class='icon icon-spinner icon-spin'></i>".html_safe }} Submit
$('.js-select-plan').click(function(event) {
event.preventDefault();
var $target = $(this),
href = $target.data('href'),
method = $target.data('method'),
formTarget = $target.attr('target'),
csrfToken = $('meta[name=csrf-token]').attr('content'),
csrfParam = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
metaData = '<input name="_method" value="' + method + '" type="hidden" />';
if (csrfParam !== undefined && csrfToken !== undefined) {
metaData += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
}
if (formTarget) {
form.attr('target', formTarget);
}
// disable button/link element
var contentMethod = $target.is('button') ? 'html' : 'val';
var replacement = $target.data('disable-with');
$target.data('ujs:enable-with', $target[contentMethod]());
if (replacement !== undefined) {
$target[contentMethod](replacement);
}
$target.prop('disabled', true);
form.hide().append(metaData).appendTo('body');
setTimeout(function(){
form.submit();
}, 50);
});
这就像在所有浏览器魅力。为了获得更好的灵活性,您可能需要将其封装在助手中。
您在Gemfile中包含了“jquery-rails”吗? –
是的,我有jQuery的铁轨(2.1.4)宝石 –
什么HTML生成的'submit_tag'?那个页面上包含了哪些JavaScript? –