Disabling button after disable_with

天涯浪子 提交于 2019-12-12 17:30:10

问题


In my Rails app, I use the :disable_with helper on a form button.

That form works via ajax. If the object is created successfully, I want to keep that button disabled. So in my create.js.erb file I have: $('#my-button').disabled = true;.

However, it doesn't work (works fine in the console though).

I suspect its interfering with Rails' JS for the disable_with helper. How can I get around that?


回答1:


Use jQuery's .prop() method to set the disabled property of the button. In your case, the code should be

$('#my-button').prop('disabled', true);

To prevent the :disable_with helper from enabling the button again, remove the data-disable-with attribute from the button:

$('#my-button').removeAttr('data-disable-with');


来源:https://stackoverflow.com/questions/16369337/disabling-button-after-disable-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!