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| %> ... <button onclick="<%= remote_function( :url=>{:action=>'my_thing', :id=>@account.id}, :method=>'post', :submit=>'my_inputs') %>">Add to List</button> ... <% 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| %> ... <button onclick="<%= remote_function( :url=>{:action=>'my_thing', :id=>@account.id}, :method=>'post', :submit=>'my_inputs') %>">Add to List</button> ... <% end %>
Is this the expected behavior when a remote function is nested inside a form?
Thanks, Jeff