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?


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,,
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

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

where “form” in the serialization is your form.


On Jul 12, 10:20 am, “[email protected][email protected]