on Rails的方式与QUOT点菜红宝石;?;如何禁用表单提交按钮&QUOT [英] How to disable a form submit button "a là Ruby on Rails Way"?

查看:195
本文介绍了on Rails的方式与QUOT点菜红宝石;?;如何禁用表单提交按钮&QUOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Ruby on Rails 3和我想的禁用的toogle的CSS类的 form.submit 当表单是AJAX提交,直到AJAX HTTP请求完成的(我使用的是默认的jQuery框架的JavaScript)。

I am using Ruby on Rails 3 and I would like to disable and toogle the CSS class of a form.submit when the form is AJAX submitted and until the AJAX HTTP request is completed (I am using the default jQuery framework for JavaScript).

我的格式如下:

<%= form_for(@article, :remote => true) do |form| %>
    ...
    <%= form.submit(nil, {:id => 'button_id', :class => 'button_class'}) %>
<% end %>

如何让我在一个共同/好/正确的方式?

推荐答案

Rails的jQuery的桥(jquery_ujs.js)code实际上有一个帮手这一点。

The Rails jQuery bridge (jquery_ujs.js) code actually has a helper for this.

<%= form.submit "Save", id: "button_id", class: "button", disable_with: "Submitting..."

它将取代按钮上的文字与你给的值。

It will replace the button text with the value you give.

请参阅<一href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag">http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag

API的变化:作为勒南建议在下面留言,为<一href="https://github.com/rails/rails/blob/v4.0.0.beta1/actionpack/lib/action_view/helpers/form_tag_helper.rb#L426">Rails 4测试版没有对 disable_with 选项去precation通知。应当改为一个数据属性:

API change: as Renan suggests in a comment below, as of Rails 4 beta there is a deprecation notice on the disable_with option. It should be changed to be a data attribute:

<%= form.submit "Save", id: "button_id", class: "button", data: {disable_with: "Submitting..."} %>

这应该与所有最新的Rails的版本,因为它是什么样的选择呢做。因此,这将是一个都不能少德precation通知,当你升级到Rails的修正4:)

This should work with all recent versions of Rails as it's what the option did anyway. So it'll be one less deprecation notice to fix when you upgrade to Rails 4. :)

这篇关于on Rails的方式与QUOT点菜红宝石;?;如何禁用表单提交按钮&QUOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆