Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is disable_with not working for a rails form_for?

My form looks like this:

<%= form_for(@foobar) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>

          ~~~form stuff~~~

  <%= submit_tag "submit",  data => { disable_with: "Processing" }, :class => "btn btn-info btn-block" %>
<% end %>

I'm running rails 3.2.11. I have the jquery-rails gem installed and all my other jQuery stuff works. Why am I still able to hit the "submit" button multiple times while it's still loading? How do I disable the button?

like image 810
brojsimpson Avatar asked Sep 03 '25 07:09

brojsimpson


2 Answers

Check the following in your raw html:

  • the submit button has data-disable-with attribute
  • your page includes jQuery js. For me I have:
    • https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  • you page includes jquery_ujs js. For me I have:
    • /javascripts/jquery_ujs.js

You can read more on https://github.com/rails/jquery-ujs.

like image 105
konyak Avatar answered Sep 04 '25 21:09

konyak


<%= button_tag 'submit', data: { disable_with: "Processing..." }, class: 'btn btn-info btn-block' %>
like image 29
Charlie Avatar answered Sep 04 '25 20:09

Charlie