Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent double click with disable_form, ruby on rails

I'm trying to prevent a form from being "double posted", when the user either clicks twice or hits submit twice.

I've seen a couple posts on this, but they haven't hit this issue per se. I can't seem to get the below to stop double-posts, and I'm getting the feeling it's related to the remote => true (using ajax to show the content on the page).

Below is my form:

    <%= form_for([@posts, @comment], :remote => true) do |f| %>

      <%= f.text_field :comment %>

      <%= f.submit "Submit", class: "btn btn-large btn-primary", :style => 'display: none;', :disable_with => '' %>

    <% end %>

Any recommendations would be great. Thank you!

like image 569
user749798 Avatar asked Jul 30 '12 02:07

user749798


1 Answers

Use the disable_with option

<%= submit_tag :submit, :id => 'submit_button', :value => "Create!", disable_with: "Creating..." %>
like image 169
YaBoyQuy Avatar answered Oct 03 '22 21:10

YaBoyQuy