Question : Rails: Ajax disable/enable submit button

I am trying to get my submission form to disable it's submit button until turned back on by RJS.  Here is how I am doing it and if someone can suggest a solution that would be great.  i just need to keep people from submitting the same thing twice while it is processing the data.

I'd like to disable it when the user clicks on the button and then send back a "re-enable" command after it is complete as the last line of the RJS render.

Thanks,
Grant
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
In the template:
 
<% remote_form_for :entry, :url => { :action => 'stuffAdd'} do |f| %>
<%= f.text_area(:data, options={:cols => 80}) %>
<%= submit_tag(value="Add Stuff") %>
<% end %>
 
 
In the App:
 
render :update do |page|
	page.insert_html :top, "result", render(:partial=>'resultPartial', :collection=> @resultList)
end
Open in New Window Select All

Answer : Rails: Ajax disable/enable submit button

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
# Submit tag takes a parameter to disable the button after it is clicked:
# :disable_with - Value of this parameter will be used as the value for a disabled version
 
submit_tag ("Submit Me!", :disable_with => "Already submitted!", :id => "submit_button")
 
# You COULD use javascript to change the caption of the button and re-enable it.
# Or, you can just re-render the button and replace it
render :update do |page|
  page.insert_html :top, "result", 
      render(:partial=>'resultPartial', :collection=> @resultList)
  page.replace :submit_button, 
      :inline => "<%= submit_tag ("Submit Me!", :disable_with => "Already submitted!") %>"
end
# If you're going to do this more than once, make it a partial so you don't have to repeat it over and over
Open in New Window Select All
Random Solutions  
 
programming4us programming4us