【问题标题】:Simple_Form multiple rows of several input with single label at topSimple_Form 多个输入的多行,顶部带有单个标签
【发布时间】:2016-07-27 14:51:53
【问题描述】:

我有一个与我的表单关联的嵌套表,所以我有一个新的食谱表单和嵌套的成分。我正在尝试将我的表单转换为使用 simple_form 并尝试使其具有单个标签的字段并且这些字段是内联的(如果需要,我有 javascript 按钮可以添加更多行成分)

编辑:

所以摆脱了 simple_form 中的标签,让它大部分工作,但现在我无法让它将新行添加为行,而是将其作为单个列。这是我的代码:

<table>
    <tr>
      <th>Ingredient Name</th>
      <th>Info (sliced,minced,etc)</th>
      <th>Amount</th>
      <th>Unit</th>
    </tr>
    <%= f.fields_for :recipe_ingredients do |builder| %>
      <%= render 'recipe_ingredient_fields', f: builder %>
    <% end %>
    <tr>
      <td><%= link_to_add_fields "Add Ingredient", f, :recipe_ingredients,"", "Add a new Ingredient" %></td>
    </tr>
</table>

成分偏:

<tr>
  <td><%= f.input :ingredient, label: false %></td>
  <td><%= f.input :info, label: false %></td>
  <td><%= f.input :format_amount, label: false %></td>
  <td><%= f.input :unit, label: false %></td>
  <td><%= f.input :_destroy, as: :hidden, label: false %></td>
  <td><%= link_to "Remove", '#', :onclick => h("remove_fields(this)"), class: "btn", title: "Remove Ingredient", remote: true %></td>
</tr>

还有 javascript 代码:

function add_fields(link, association, content){
    var new_id = new Date().getTime();
    var regexp = new RegExp("new_" + association, "g");
    $(link).before(content.replace(regexp, new_id));
}

这会将其添加到第一列中的所有字段中...我知道我需要调整前一行但不确定要选择什么来选择行而不是元素

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    根据我的阅读,您似乎需要一些柔软的表格形式(在表格中读取),如果是这种情况,您可以使用普通 html 构建表格并使用 f.input_field 而不是 f.input 这种方法会给你单独的字段,没有 HTML 的其余部分:包装器等。

    你想要这个吗?包装器 HTML 也用于显示错误、提示等。错误将如何显示?您仍然可以在单元格中使用f.input,您可能只是想尝试一下。

    【讨论】:

      猜你喜欢
      • 2015-11-07
      • 2011-10-29
      • 2015-09-29
      • 2020-03-22
      • 1970-01-01
      • 2017-01-30
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多