Is it possible to have a form submit normally if button X is pushed and do an AJAX call if button Y is pushed? My use case: I''m letting users do some customizations and I want a preview button and a save button. Hitting preview submits the current form values as an AJAX call and the returned javascript generates a preview. When they are happy with the results they hit save which should just submit the form normally. I guess another option would be to have a separate form for the AJAX preview function that copies all the values from the main form. Any pointers? -- 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.
> Is it possible to have a form submit normally if button X is pushed > and do an AJAX call if button Y is pushed? > > My use case: > > I''m letting users do some customizations and I want a preview button > and a save button. Hitting preview submits the current form values > as an AJAX call and the returned javascript generates a preview. When > they are happy with the results they hit save which should just submit > the form normally. > > I guess another option would be to have a separate form for the AJAX > preview function that copies all the values from the main form. > > Any pointers?Use jQuery''s .post and .serialize methods to grab the data and submit it via ajax... then do whatever you want with it on the backend... -- 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 Mar 17, 4:39 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > Is it possible to have a form submit normally if button X is pushed > > and do an AJAX call if button Y is pushed? > > > My use case: > > > I''m letting users do some customizations and I want a preview button > > and a save button. Hitting preview submits the current form values > > as an AJAX call and the returned javascript generates a preview. When > > they are happy with the results they hit save which should just submit > > the form normally. > > > I guess another option would be to have a separate form for the AJAX > > preview function that copies all the values from the main form. > > > Any pointers? > > Use jQuery''s .post and .serialize methods to grab the data and submit it via ajax... then do whatever you want with it on the backend...Sweet. Thanks for the serialize tip! simple preview link calls preview() <a href="#" onclick="preview()">Preview</a> preview posts the form data <%= javascript_tag do %> function preview() { $.post("/sites/<%=-lAcQvMfiUYM@public.gmane.org%>/preview", $(''#add-site'').serialize()); return false; } <% end %> and I''m all set. -- 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.