Why does an RJS call within a form cause submit the form's s

I have a page with a large form. The form is created using form_for.
Within the form, I have several button tags (not submit tags). Each
button has a remote_function call in the onclick event. When a button
is clicked, the remote function is executed, but the RJS tempate is
not invoked. Moreover, the form’s action method is invoked on the
server after the remote function (as though the form is being
submitted). So there are two problems in this scenario: 1) my remote
function is executed, but the corresponding RJS template is not
executed; 2) the action specified by the form also fires. The code
looks something like this:

<% form_for(:account, :url => rule_path(@account), :html => {:method
=> :put, :id => ‘rules_form’}) do |f| %>

Add to
List

<% end %>

To fix this I replacing the form_for tag with remote_form_for. In
this scenario, I get better results: the RJS template is executed
after the remote function call. But I still have one problem: the
form’s action methods are still executed. The code looks like this:

<% remote_form_for(:account, :url => rule_path(@account), :html =>
{:method => :put, :id => ‘rules_form’}) do |f| %>

Add to
List

<% end %>

Is this the expected behavior when a remote function is nested inside
a form?

Thanks,
Jeff

Jeff
How do u render “submit” action in controller ?

respond_to ?

The problem was in my button tags: the default type attribute for a
button is “submit”, so my button tags need to look like this:

Add to List

When the “submit” button is clicked, the URL in the action attribute
of the form tag will be submitted to the server. So in my example,
the update method in the rules_controller is executed.

On Sep 16, 4:05 am, “alexey.Creopolis” [email protected]

thanks for the post - i was wondering about this one.

You should look at button_to_function. It will do exactly what you want
including setting the type to button.

http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#M000631

Ivor P. wrote:

                                        :url=>{:action=>'my_thing',
:id=>@account.id <http://account.id>},
                                        :method=>'post',
:submit=>'my_inputs')
%>">Add to List</button>





>


Sincerely,

William P.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs