rails 3.1 submit an ajax (remote: true) form with a link

前端 未结 1 509
南笙
南笙 2021-01-21 08:07

Working with ajax on a rails 3.1 app, i need to be able to submit an ajax form (with remote: true) using a link rather than a submit button.

what do i need to do to the

相关标签:
1条回答
  • 2021-01-21 08:46

    When you create a form with :remote => true the Ajax event is bound to the submit button of the form. You must use javascript to trigger that event. Here is some code I used to accomplish something similar:

    <%= form_for [item.list, item], :remote => true, :html => { :'data-type' => 'json', :id => 'change-completed-form' } do |f| %>
        <td><%= f.label :name, item.name %></td>
        <td><%= f.check_box :completed, :onClick => "this.form.submit_button.click();" %></td>
        <%= f.submit :id => 'submit_button', :style => 'display: none;' %>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题