I have a case that a form has two submit button, one is edit button that only change the current div that can use form_remote_tag, the other is delete button that should refresh the whole page that can use form_tag. But I what use edit and delete button both in a form, how can I do that? -- http://sourceforge.net/projects/mycodeline/ --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/21/07, huang zhimin <flyerhzm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a case that a form has two submit button, > one is edit button that only change the current div that can use > form_remote_tag, > the other is delete button that should refresh the whole page that can use > form_tag. > > But I what use edit and delete button both in a form, how can I do that? > > --I think javascript is the only way I can think of. One way would be to load the page, and then attach an event listener to the submit event of the form. Then you detect if it''s an edit click, in which case make an ajax request and the stop the event with Event.stop( event ). If it''s the delete button do nothing and let the form take it''s natural course. Daniel --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
typically if you''re going to use more than one submit button inside a form, then you can check to see which was clicked in two ways: 1. name both buttons the same, and check which value is posted <form> <input type=''submit'' name=''btnSubmit'' value=''submit one'' /> <input type=''submit'' name=''btnSubmit'' value=''submit two'' /> </form> if params[:btnSubmit] == "submit one" ... do this ... else ... do that ... end 2. name the buttons differently, and see which posts a value <form> <input type=''submit'' name=''btnSave'' value=''Save'' /> <input type=''submit'' name=''btnCancel'' value=''Cancel'' /> </form> if params[:btnSave] ... do this ... elsif params[:btnCancel] ... do that ... end personally I tend to use method # 2 On Jun 20, 10:30 pm, "huang zhimin" <flyer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a case that a form has two submit button, > one is edit button that only change the current div that can use > form_remote_tag, > the other is delete button that should refresh the whole page that can use > form_tag. > > But I what use edit and delete button both in a form, how can I do that? > > --http://sourceforge.net/projects/mycodeline/--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
I got it. <% form_tag :action => "destroy" do %> <table> <% for category in @categories %> <tr> <td width="10%"><%= radio_button ''category'', ''id'', category.id %><%h category.name %></td> </tr> <% end %> </table> <%= submit_to_remote ''edit'', ''Edit'', :update => ''category'', :url => { :action => ''edit'' } %> <%= submit_tag ''Delete'' %> <% end %> edit button is submit_to_remote which is asynchronized and delete button is submit_tag that will refresh the whole page On 6/21/07, jemminger <jemminger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > typically if you''re going to use more than one submit button inside a > form, then you can check to see which was clicked in two ways: > > 1. name both buttons the same, and check which value is posted > <form> > <input type=''submit'' name=''btnSubmit'' value=''submit one'' /> > <input type=''submit'' name=''btnSubmit'' value=''submit two'' /> > </form> > > if params[:btnSubmit] == "submit one" > ... do this ... > else > ... do that ... > end > > 2. name the buttons differently, and see which posts a value > <form> > <input type=''submit'' name=''btnSave'' value=''Save'' /> > <input type=''submit'' name=''btnCancel'' value=''Cancel'' /> > </form> > > if params[:btnSave] > ... do this ... > elsif params[:btnCancel] > ... do that ... > end > > personally I tend to use method # 2 > > > On Jun 20, 10:30 pm, "huang zhimin" <flyer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have a case that a form has two submit button, > > one is edit button that only change the current div that can use > > form_remote_tag, > > the other is delete button that should refresh the whole page that can > use > > form_tag. > > > > But I what use edit and delete button both in a form, how can I do that? > > > > --http://sourceforge.net/projects/mycodeline/ > > > > >-- http://sourceforge.net/projects/mycodeline/ --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---