在form_for循环之外提交按钮 [英] Submit button outside form_for loop

查看:157
本文介绍了在form_for循环之外提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用twitter bootstrap设置了一些水平选项卡,并且我在每个选项卡内呈现一个表单:

I have set up some horizontal tabs using twitter bootstrap and I am rendering a form inside each of the tabs:

<div class="tab-content">
  <div id="tab1" class="tab-pane active">
      <%= render :partial => "shipdr/websites/form", locals: {:@shipdr_website => shipdr_website} %>
  </div>
  <div id="tab2" class="tab-pane">
    Another form (not yet implemented)
  </div>
  <div id="tab3" class="tab-pane">
    Another form (not yet implemented).
  </div>
</div>

然后在shipdr / websites / form中有:

Then in shipdr/websites/form I have:

<%= simple_form_for(@shipdr_website) do |f| %>
  <% if @shipdr_website.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@shipdr_website.errors.count, "error") %> prohibited this shipdr_website from being saved:</h2>

      <ul>
      <% @shipdr_website.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.input :name %>
  </div>
  <div class="field">
    <%= f.input :url %>
  </div>
  <div class="field">
    <%= f.input :api_key %>
  </div>
  <div class="actions">
    <%= f.submit nil, :class => "btn btn-primary" %>
  </div>
<% end %>

我想将提交按钮移动到标签内容区域之外,因此当用户点击提交按钮,提交所有三个表单区域。所有表格都将使用相同的模型和相同的操作,但会有不同的字段。除了我使用制表符之外,这个想法与向导类似。

I want to move the submit button outside of the "tab-content" area so when a user clicks the submit button, all three forms area submitted. All forms will use that same model and the same action but will have different field. The idea is similar to a wizard except I am using tabs.

有没有人知道如何在form_for循环之外移动submit按钮,以及如何使用一个按钮提交三个表单?

Does anyone have any idea how I can move the submit button outside of the form_for loop and how I can submit the three forms with a single button?

推荐答案

我不知道您是否可以一次提交3份表格。但您可以这样做:

I don't know if you can submit 3 forms at a time. But you can do this:

<div class="tab-content">
  <%= simple_form_for(@shipdr_website) do |f| %>
    <div id="tab1" class="tab-pane active">
      <%= render :partial => "shipdr/websites/form", locals => {:f => f, :shipdr_website => @shipdr_website} %>
    </div>
    <div id="tab2" class="tab-pane">
      Another form (not yet implemented)
    </div>
    <div id="tab3" class="tab-pane">
      Another form (not yet implemented).
    </div>
  <% end %>
</div>

并从您的偏好中删除,只留下输入。

And remove that from your partials, leaving just the inputs.

<%= simple_form_for(@shipdr_website) do |f| %>

这篇关于在form_for循环之外提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆