On a normal form one could use this logic to get which submit button was clicked. if params[:commit].include? "Preview" # do something elsif params[:commit].include? "Post" # do something else # do something end But if I use RJS and form_remote_tag then the above logic will not work. I was wondering if anyone has any solution on how to find which button was clicked when form_remote_tag is being used. Thanks. - Raj --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Raj Singh wrote:> But if I use RJS and form_remote_tag then the above logic will not work. > > I was wondering if anyone has any solution on how to find which button > was > clicked when form_remote_tag is being used. > > Thanks. > - RajI had the same problem. This is actually a prototype issue because prototype ends up passing all of the submit buttons when a form is submitted via AJAX. Until prototype is fixed (if it ever will be?), I put a hidden field in my form that contains the value of the button clicked. Each submit button has assigns a value to the hidden field when it is clicked: <%= hidden_field_tag ''which'', '''' %> <%= submit_tag ''Button1'', {:onclick => "$(''which'').value = ''button1'';"} %> <%= submit_tag ''Button2'', {:onclick => "$(''which'').value = ''button2'';"} %> In my controller, I can then check the ''which'' parameter to see which button was clicked. Note, however, that this method only works with javascript enable, so you still have to drop back to checking for submit buttons if ''which'' is empty: if params[:which].empty? #javascript must be disabled #handle params[:commit] to see which button was clicked else #javascript is enabled #handle params[:which] to see which button was clicked end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks Curtis. Thanks for posting the code and mentioning that it was prototype issue. I thought I was missing something here. -=- Raj On 9/18/06, Curtis Summers <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Raj Singh wrote: > > But if I use RJS and form_remote_tag then the above logic will not work. > > > > I was wondering if anyone has any solution on how to find which button > > was > > clicked when form_remote_tag is being used. > > > > Thanks. > > - Raj > > I had the same problem. This is actually a prototype issue because > prototype ends up passing all of the submit buttons when a form is > submitted via AJAX. Until prototype is fixed (if it ever will be?), I > put a hidden field in my form that contains the value of the button > clicked. Each submit button has assigns a value to the hidden field > when it is clicked: > > <%= hidden_field_tag ''which'', '''' %> > <%= submit_tag ''Button1'', {:onclick => "$(''which'').value = ''button1'';"} > %> > <%= submit_tag ''Button2'', {:onclick => "$(''which'').value = ''button2'';"} > %> > > In my controller, I can then check the ''which'' parameter to see which > button was clicked. Note, however, that this method only works with > javascript enable, so you still have to drop back to checking for submit > buttons if ''which'' is empty: > > if params[:which].empty? > #javascript must be disabled > #handle params[:commit] to see which button was clicked > else > #javascript is enabled > #handle params[:which] to see which button was clicked > end > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---