:onclick 和 formtastic:第一次单击后禁用提交按钮会阻止表单处理?

发布于 2025-01-05 10:40:19 字数 582 浏览 0 评论 0原文

我试图确保我的 Rails 应用程序的用户无法通过双击多次提交我的格式表单。

请参阅下面的我的代码。

不幸的是,在将 :onclick 参数添加到提交按钮后,表单不再处理。按钮名称简单更改为禁用按钮“正在处理...”(如提交期间的预期),但此状态是永久的(没有像以前一样的数据验证和重定向)。

我不知道如何调试这个 - 有人可以帮忙吗?

= semantic_form_for @case, :html => {:class => "form-stacked"} do |f|  
    = f.inputs :name => "Case" do
    = f.input  :summary, :input_html => {:class => 'xxlarge main_case'}
= f.buttons do
  = f.commit_button "Create Case", :button_html => {:class => "btn primary", :onclick => "this.disabled=true; this.value='Processing...';"}

I am trying to make sure the users of my rails app can not submit my formtastic forms multiple times by double clicking.

See my code below.

Unfortunately, after adding the :onclick argument to the commit button, the form does not process anymore. The button name simple changes to a disabled button 'Processing...' (as expected during submission) but this state is permanent (no data validation and redirect as before).

I fail to see how to debug this - can anybody help?

= semantic_form_for @case, :html => {:class => "form-stacked"} do |f|  
    = f.inputs :name => "Case" do
    = f.input  :summary, :input_html => {:class => 'xxlarge main_case'}
= f.buttons do
  = f.commit_button "Create Case", :button_html => {:class => "btn primary", :onclick => "this.disabled=true; this.value='Processing...';"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你对谁都笑 2025-01-12 10:40:19

尝试一下:

submit_tag "Create Case", :disable_with => "Processing..."

这将在 Rails 3 及更高版本中工作

更新:

使用 formattastic 您需要以下内容

<%= f.action :submit, :button_html => { :label => "create case", :class => "btn primary", :disable_with => 'Processing...' } %>

just try:

submit_tag "Create Case", :disable_with => "Processing..."

this will work in rails 3 and above

Update:

with formtastic you need the following

<%= f.action :submit, :button_html => { :label => "create case", :class => "btn primary", :disable_with => 'Processing...' } %>
耶耶耶 2025-01-12 10:40:19

如果您没有使用 Rails 3,您实际上希望在表单元素上的“onsubmit”上执行此操作,因为在文本字段等中按 Enter 键可以触发提交事件。

确保在 js 代码中“返回 true”,以便在禁用按钮后实际提交表单。

If you are not using rails 3, you would actually want to do that on "onsubmit" on the form element, since pressing enter keys in text fields etc can trigger submit event.

Make sure you "return true" in your js code for the form to actually submit after you disable the button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文