Mpeychich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-12  17:20 UTC
remote_form_for behavior on javascript submit();
Hey all,
Tried this on the IRC channel but after an hour i figured nobody that
was on knew, so i''ll try it here.  I have a rhtml page with:
<% remote_form_for(:performance_goal, :url =>
user_performance_goal_path(@user.account, @user,
@performance_goal), :html => {:id => ''sidebar_form'',
:method => :put})
do |f| %>
<%= f.text_area :impact, :size => ''25x3'', :onchange
=>
"this.form.submit();" %>
<% end %>
please know that the :method => :put is in there to send the request
to my RESTful update method.  When i change the text area it does in
fact submit the form, but not through AJAX.  Instead it sends it as a
normal html form and ignores the onsubmit attribute which reads:
onsubmit="new
Ajax.Request(''/accounts/1/users/1/gss/performance_goals/
1'', {asynchronous:true, evalScripts:true,
parameters:Form.serialize(this)}); return false;"
Ive tried using the observe_form helper and it behaves the same way.
The only way i can have it submit through AJAX is by using a submit
button.  How can i submit the remote_form_for form via javascript and
have it still perform the AJAX request?
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
-~----------~----~----~----~------~----~------~--~---
Hello Mpeychich,
This is not a rails problem nor a problem in your code.  There is
browser non-compliance to the submit() action which Steve Nyholm has
documented here,
http://blogs.vertigosoftware.com/snyholm/archive/2006/09/27/3788.aspx,
so what occurs is submit() does not call the onsubmit event handler
that the ajax request is bound to.
I can see two potential solutions to this
(1) do not call form.submit but instead generate the ajax on your own
with something such as,
"#{remote_function(:url =>user_performance_goal_path(@user.account,
@user, @performance_goal))}; return false;"
(2) explicitly call the forms onsubmit event handler with some
javascript
The problem with solution (1) is that this WILL NOT serialize your
form elements, which is general something you want and often something
you need.  To serialize your form elements use the following,
"#{remote_function(:url =>user_performance_goal_path(@user.account,
@user, @performance_goal), :with => "Form.serialize(form)" )};
return
false;"
where "form" in the serialization is your form.
Peter
On Jul 12, 10:20 am,
"Mpeych...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<Mpeych...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hey all,
>
> Tried this on the IRC channel but after an hour i figured nobody that
> was on knew, so i''ll try it here.  I have a rhtml page with:
>
> <% remote_form_for(:performance_goal, :url =>
> user_performance_goal_path(@user.account, @user,
> @performance_goal), :html => {:id =>
''sidebar_form'', :method => :put})
> do |f| %>
>
> <%= f.text_area :impact, :size => ''25x3'', :onchange
=>
> "this.form.submit();" %>
>
> <% end %>
>
> please know that the :method => :put is in there to send the request
> to my RESTful update method.  When i change the text area it does in
> fact submit the form, but not through AJAX.  Instead it sends it as a
> normal html form and ignores the onsubmit attribute which reads:
>
> onsubmit="new
Ajax.Request(''/accounts/1/users/1/gss/performance_goals/
> 1'', {asynchronous:true, evalScripts:true,
> parameters:Form.serialize(this)}); return false;"
>
> Ive tried using the observe_form helper and it behaves the same way.
> The only way i can have it submit through AJAX is by using a submit
> button.  How can i submit the remote_form_for form via javascript and
> have it still perform the AJAX request?
>
> 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
-~----------~----~----~----~------~----~------~--~---