Hi all, I have a ajax form creating by "form_remote_for", whose url is to create a new model by default. The page doesn''t change after the ajax call on submit button so the form is still there after the new model is created. But if I submit the form for the second time, I want to update the formerly created model using an Ajax post. I think I could render an rjs at the end of the first submit action and the rjs should change the onsubmit event handler of the form, say: page[:form][:onsubmit] = article_path(@article) but it seems that this doesn''t work. Another problem is that "article_path(@article)" will generate something like "/article/12" with HTTP PUT method, but I need something like "new Ajax.Request(...)". Any idea about these two questions? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne
2007-May-09 17:24 UTC
Re: How can I change a form''s onsubmit event handler using r
allen wrote:> Hi all, > > I have a ajax form creating by "form_remote_for", whose url is to > create a new model by default. The page doesn''t change after the ajax > call on submit button so the form is still there after the new model > is created. But if I submit the form for the second time, I want to > update the formerly created model using an Ajax post. > > I think I could render an rjs at the end of the first submit action > and the rjs should change the onsubmit event handler of the form, say: > > page[:form][:onsubmit] = article_path(@article) > > but it seems that this doesn''t work. Another problem is that > "article_path(@article)" will generate something like "/article/12" > with HTTP PUT method, but I need something like "new > Ajax.Request(...)". Any idea about these two questions? Thanks.page[:form].onsubmit = remote_function(:url => article_path(@article), ...) Although, you are probably better off rendering a partial that replaces your form setup they way you want for edits, instead of creation. page[:form].update :partial => ''edit_form'' -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Changing the onsubmit event using an RJS template
- [Prototype] Why doesn''t calling submit() on a form result in the execution of the onsubmit event handler?
- form_remote_tag :onsubmit not working.
- form_remote_for NOT passing param: I want put and I get post
- Using onSubmit tag in form_tag?