【问题标题】:Remove label in a nested_form_for删除 nested_form_for 中的标签
【发布时间】: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 =&gt; false),因此它可以在表格内工作。我知道这是一个 jQuery 调用。我可以通过label: "My New Label" 修改标签,但label: falselabel: "" 只生成默认字段名称。

所以我想我在这部分有两个问题要问fields_for

  1. 我可以去掉标签吗?
  2. 如何修改部分? (我看到你可以修改它,但我找不到任何代码使用示例)。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 哇。我花了很长时间才找到这个!谢谢!
    猜你喜欢
    • 2020-02-26
    • 2016-02-22
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 2013-02-18
    • 2018-02-10
    相关资源
    最近更新 更多