Rails 4:单击后禁用提交按钮 [英] Rails 4: Disable submit button after click

查看:112
本文介绍了Rails 4:单击后禁用提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个form_tag(foo_path(@foo), remote: true, id: 'foo-form'表单和一个提交按钮submit_tag ("Submit", :id => "foo-submit")

I have a form_tag(foo_path(@foo), remote: true, id: 'foo-form' form and a submit button submit_tag ("Submit", :id => "foo-submit")

在单击提交按钮后,我想禁用它.显然,我不能使用onlick="jQuery(this).prop('disabled', true);"之类的东西,因为它会破坏远程功能.我知道submit_tag的:disable_with数据属性,但它似乎不适用于我.它确实会生成正确的表单代码,但无效.我不确定为什么它不起作用,但这可能是由于我同时使用了原型(遗留原因)和jQuery.虽然,我只为jQuery而不是为原型加载ujs.但是,所有其他query_ujs功能都可以很好地工作.

I'd like to disable the submit button after it has been clicked. Obviously, I cannot use something like onlick="jQuery(this).prop('disabled', true);" because it would break the remote functionality. I'm aware of the :disable_with data attribute for the submit_tag but it doesn't seem to work for me. It does generate the right form code but it has no effect. I'm not sure why it doesn't work but it might be due to the fact that I use prototype (legacy reasons) and jquery at the same time. Though, I only load ujs for jquery and not for prototype. However, all other query_ujs features work very well.

还有另一种禁用提交按钮的方法吗?

Is there another way to disable the submit button?

推荐答案

问题是由无效的HTML代码引起的.参见< div>破坏< form> disable_with现在可以使用

The problem was caused by invalid HTML code. See <div> breaks <form> disable_with works now

这篇关于Rails 4:单击后禁用提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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