I''m having a problem with a submit event What I''m trying to do is to update a record using radio inputs... and everything is ok, but when I do a fast double-click on the radio button, the form duplicates and I''m not sure if its a javascript problem or a rails problem cause its rendering the partial again (which shouldn''t be happening) Somebody had this problem before or know how to fix it? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 January 2012 16:33, JavierQQ <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m having a problem with a submit event > What I''m trying to do is to update a record using radio inputs... and > everything is ok, but when I do a fast double-click on the radio > button, the form duplicates and I''m not sure if its a javascript > problem or a rails problem cause its rendering the partial again > (which shouldn''t be happening)Look in the rails log to see what is happening (development.log assuming in development mode). Once you understand what is happening you will be better placed to fix it. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jan 5, 2012 at 11:44 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Look in the rails log to see what is happening (development.log > assuming in development mode). > Once you understand what is happening you will be better placed to fix it. > > Colin > >Yes, I''ve done that and every time I click on that radio... it makes an update and it saves the chosen option, if I make 2 fast clicks (or N clicks) it renders 2 (or N ) partials. In my log after doing the update in database, it renders the partial and after that it calls the update.js that I use, is there a way to avoid this behavior? or it something related to the javascript? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. Fra: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] På vegne af Javier Quarite Sendt: 5. januar 2012 17:55 Til: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Emne: Re: [Rails] Duplicate forms after click On Thu, Jan 5, 2012 at 11:44 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org<mailto:clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> wrote: Look in the rails log to see what is happening (development.log assuming in development mode). Once you understand what is happening you will be better placed to fix it. Colin Yes, I''ve done that and every time I click on that radio... it makes an update and it saves the chosen option, if I make 2 fast clicks (or N clicks) it renders 2 (or N ) partials. In my log after doing the update in database, it renders the partial and after that it calls the update.js that I use, is there a way to avoid this behavior? or it something related to the javascript? 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com<mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pretty sure that its not ruby on rails problem. its maybe because of your javascript or maybe try to read your codes again On Jan 6, 3:00 pm, Brynjolfur Thorvardsson <bi...-6eh5JQIm30aHXe+LvDLADg@public.gmane.org> 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. > > Fra: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] På vegne af Javier Quarite > Sendt: 5. januar 2012 17:55 > Til: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Emne: Re: [Rails] Duplicate forms after click > > On Thu, Jan 5, 2012 at 11:44 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org<mailto:clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> wrote: > > Look in the rails log to see what is happening (development.log > assuming in development mode). > Once you understand what is happening you will be better placed to fix it. > > Colin > > Yes, I''ve done that and every time I click on that radio... it makes an update and it saves the chosen option, if I make 2 fast clicks (or N clicks) it renders 2 (or N ) partials. > > In my log after doing the update in database, it renders the partial and after that it calls the update.js that I use, is there a way to avoid this behavior? or it something related to the javascript? > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> . > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com<mailto:rubyonrails-talk+unsub scribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > For more options, visit this group athttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 6, 2012 at 2:00 AM, Brynjolfur Thorvardsson <binni-6eh5JQIm30aHXe+LvDLADg@public.gmane.org>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] }, :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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] På vegne af Javier Quarite Sendt: 6. januar 2012 12:44 Til: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Emne: Re: [Rails] Duplicate forms after click On Fri, Jan 6, 2012 at 2:00 AM, Brynjolfur Thorvardsson <binni-6eh5JQIm30aHXe+LvDLADg@public.gmane.org<mailto:binni-6eh5JQIm30aHXe+LvDLADg@public.gmane.org>> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com<mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Is there a way to control multiple ajax requests?, I''ve tried google but as far as I get there''s a stop() but it''s not what I need in my case. I hope to find the solution and post it here then 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''m using the very old trick: // Prevent double click $(''form'').submit(function(){ $(''input[type=submit]'', this).attr(''disabled'', ''disabled''); }); -- Daniel Negri e: danielgomesnegri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <danielnegri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> d: +55 61 8494 1441 Skype: danielnegri Follow me on Twitter <http://twitter.com/#!/danielnegri> On Fri, Jan 6, 2012 at 10:34 AM, Brynjolfur Thorvardsson <binni-6eh5JQIm30aHXe+LvDLADg@public.gmane.org>wrote:> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto: > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] *På vegne af *Javier Quarite > *Sendt:* 6. januar 2012 12:44 > > *Til:* rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > *Emne:* Re: [Rails] Duplicate forms after click**** > > ** ** > > ** ** > > On Fri, Jan 6, 2012 at 2:00 AM, Brynjolfur Thorvardsson <binni-6eh5JQIm30aHXe+LvDLADg@public.gmane.org> > 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] }, :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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 6, 2012 at 8:43 AM, Daniel Negri <danielgomesnegri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I''m using the very old trick: > > // Prevent double click > > $(''form'').submit(function(){ > > $(''input[type=submit]'', this).attr(''disabled'', ''disabled''); > > }); > >That would work if I had a submit button =) The scenario is a ... Exam Question, wich has 4 alternatives. After click on an alternative it automatically saves/updates(only happens if its already checked) And now when I want to do this function submit_with_ajax(t){ $("#myForm").submit(function(){ alert("hi"); }); } nothing happens. I''m trying to change that alert with an $.ajax() method in order to do something after complete 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 6, 2012 at 10:31 AM, Javier Quarite <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The scenario is a ... Exam Question, wich has 4 alternatives. After click on > an alternative it automatically saves/updates(only happens if its already > checked)If you just want to save the state of that radio button, why are you returning anything to the browser at all? And even if you wanted to refresh the page content from that partial, if it''s rendering twice you have a targeting problem in your JS, like you''re adding the form to the DOM instead of replacing the original, or something. Regardless, the right thing should happen even with multiple clicks in a short time period (so trying to prevent that is pointless, IMO). Can you come up with a *simple* test case that demonstrates this problem? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 6, 2012 at 2:26 PM, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jan 6, 2012 at 10:31 AM, Javier Quarite <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > The scenario is a ... Exam Question, wich has 4 alternatives. After > click on > > an alternative it automatically saves/updates(only happens if its already > > checked) > > If you just want to save the state of that radio button, why are you > returning anything to the browser at all? > > I''m not just only saving the state in order to make the submit after Ifinish the entire exam. When I click on letter B (for example) in my Answer table that question got "B" I have to return this because they may change their answers ( and that might be my problem and I''m really considering hide that div)> And even if you wanted to refresh the page content from that partial, > if it''s rendering twice you have a targeting problem in your JS, like > you''re adding the form to the DOM instead of replacing the original, > or something. > > Regardless, the right thing should happen even with multiple clicks > in a short time period (so trying to prevent that is pointless, IMO). > > Can you come up with a *simple* test case that demonstrates this > problem? > -- >I''m not sure what you mean by simple test :) but lets say someone just click that radio 2 times quickly (not that he/she meant to do that) and suddendly it appears another set of alternatives. As you mention, try to prevent multiple requests may be not the problem (or maybe not here) and I just tried to do this $(''#edit_response_set_''+t).submit(); $("#edit_response_set_"+t).slideUp(300).fadeIn(400); It''s just hiding and showing the form... and I think is the easy solution I can get Anyway, thanks for your responses... hope you understood what I tried to do :) 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.