【发布时间】:2016-03-03 13:32:45
【问题描述】:
我似乎无法以正常方式删除nested_fields_for 中的标签。正常的方法是标记它label: false。
= bootstrap_nested_form_for @quote, label_errors: true, label_col: "col-sm-2", control_col: "col-sm-6" do |f|
=f.text_field :quote_number, value: (@quote.quote_number || next_quote_number), prepend: "<i class='fa fa-tag'></i>".html_safe, control_col: "col-md-6", label: false, class: "input-sm"
=f.collection_select :customer_id, my_customers, :id, :company_name, {control_col: "col-md-7", include_blank: "Select Customer", label: false}, {class: "input-sm"}
%table.table.table-condensed{style: "margin-bottom:0px;"}
%tbody#things
= f.fields_for :things, :wrapper => false, label_errors: true, html: {class: 'form_inline'} do |thing|
%tr.fields
%td{style: "width:100px;border-top:none;"}
= perm.text_field :quote_amount, value: number_with_precision(perm.object.quote_amount, precision: 2), prepend: "<i class='fa fa-dollar'></i>".html_safe, label: false, class: "input-sm", label: false
%td{style: "border-top:none;"}
= perm.collection_select :cat_id, my_categories, :id, :name, include_blank: "Select Category", label: false}, {class: "input-sm"}
%td{style: "text-align: right; padding-top: 10px;border-top:none;"}
%br/
= perm.link_to_remove "<i class='fa fa-close'></i>".html_safe, class: "btn btn-danger btn-sm"
= f.link_to_add "<i class='fa fa-plus'></i> Add Thing".html_safe, :things, "data-target" => "#things", class: "btn btn-success btn-sm"
然后,在fields_for 内部,这也不起作用。我已经删除了包装器 (:wrapper => false),因此它可以在表格内工作。我知道这是一个 jQuery 调用。我可以通过label: "My New Label" 修改标签,但label: false 和label: "" 只生成默认字段名称。
所以我想我在这部分有两个问题要问fields_for。
- 我可以去掉标签吗?
- 如何修改部分? (我看到你可以修改它,但我找不到任何代码使用示例)。
【问题讨论】:
标签: jquery ruby-on-rails ruby-on-rails-4 haml nested-form-for