Hi, I'm not really that familiar with rails/javascript integration. You are 
using a radiobutton to submit a form, and using the onClick event, have you 
considered simply using an input button instead? My suggestion about using a 
delay probably wouldn't work, what would you delay and where?

When you click rapidly on the radiobutton, the onClick events fires each time 
causing a fresh submit. Rails simply accepts these submits and sends the 
appropriate pages back. You could have a global variable in your javascript, 
e.g. "submitted=false" and then set this to true on first submit and check it 
before each submit.  The variable would be set to true again each time the page 
refreshes, if you need to reset it when a partial is loaded then just include a 
bit of javascript in that partial that resets the variable.


Fra: rubyonrails-talk@googlegroups.com 
[mailto:rubyonrails-talk@googlegroups.com] På vegne af Javier Quarite
Sendt: 6. januar 2012 12:44
Til: rubyonrails-talk@googlegroups.com
Emne: Re: [Rails] Duplicate forms after click


On Fri, Jan 6, 2012 at 2:00 AM, Brynjolfur Thorvardsson 
<bi...@itanet.nu<mailto:bi...@itanet.nu>> wrote:
Hi, this sounds like a javascript problem. Javascript is executed 
asynchroniously on your browser so clicking fast means that you are sending 
more than one submit from the same form, causing Rails to return more than once 
from the controller. There are probably many ways to avoid this but one is to 
put in a delay of say half a second in your javascript submit code.


Yes, that's what I found. I send a lot of ajax request because the function 
that do the submit is this

function save_response_with_ajax(t){
                      $('#edit_response_set_' + t).submit();
}

I think that its way to simple and without any kind of validation and the radio 
button is this

<%= rs_a_form.input :answer_id, :collection => 
response_set.question.answers.map { |a| [build_choice(a) , a.id<http://a.id>] 
}, :as => :radio, :input_html => {:onclick => 'save_response_with_ajax(' + 
response_set.id.to_s + ');'} %>

Should I change that submit() into a $.ajax() ?

Thanks

Javier
--
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to 
rubyonrails-talk@googlegroups.com<mailto:rubyonrails-talk@googlegroups.com>.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com<mailto:rubyonrails-talk+unsubscr...@googlegroups.com>.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to