删除nested_form_for中的标签

时间:2015-11-30 00:12:44

标签: jquery ruby-on-rails ruby-on-rails-4 haml nested-form-for

我似乎无法在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: falselabel: ""仅生成默认字段名称。

所以我想这部分fields_for有2个问题。

  1. 我可以删除标签吗?
  2. 如何修改部分? (我看到你可以修改它,但我找不到代码用法的任何例子。)

1 个答案:

答案 0 :(得分:0)

要在Rails表单字段中删除标签,应使用skip_label: true作为附加属性。