Rails通过单击单选按钮提交远程表单

时间:2021-07-29 20:08:26

I have a form that submits when you chose a radio button (below). Currently the page refreshes when it submits and I'd like to use Jquery and remote submission so it doesn't refresh. Any idea where to start with this?

我有一个表单,当你选择单选按钮时(下面)。目前,页面提交时会刷新,我希望使用Jquery和远程提交,这样它就不会刷新。你知道从哪里开始吗?

<%= simple_form_for(@order) do |f| %>
    <%= f.input :orderstatus_id, :as => :radio, :label => false do %>
        <% current_user.account.orderstatuses.order(:status_order).each do |os| %>
        <p id="invoice-color-select">
                <%= f.radio_button :orderstatus_id, os.id, :class => 'selector', :onclick => "this.form.submit();" %>
                <%= f.label "#{os.name}", :style => "background: ##{os.color}", :class => 'status' %>
    </p>
      <% end %>
    <% end %>

    <div style="margin-top:20px">
        <% if !current_user.account.has_plan? || current_user.account.plan_key== "ultra" %>
            <a class="fancybox" href="#editstatus">Edit</a>
        <% end %>
    </div>
<% end %>

1 个解决方案

#1


3  

I added this into my view:

我在我的观点中加入了这一点:

<%= f.radio_button :orderstatus_id, os.id, :class => 'selector', :onclick => "this.form.submit();" %>

You can see the :onclick portion here.

您可以在这里看到:onclick部分。

#1


3  

I added this into my view:

我在我的观点中加入了这一点:

<%= f.radio_button :orderstatus_id, os.id, :class => 'selector', :onclick => "this.form.submit();" %>

You can see the :onclick portion here.

您可以在这里看到:onclick部分。