4

在 simple_form 自定义包装器中,您可以生成一个没有包装器及其相应标签的输入字段吗?

目前,我的自定义包装器如下所示:

config.wrappers :category_tab, tag: "ul", class: "inline-list" do |ul|                                                                                                                         
  ul.use :html5                                                                                                                                                                             
  ul.wrapper tag: "li" do |li|                                                                                                                                                              
    li.wrapper tag: "label", class: "faux-tab" do |label|                                                                                                                                     
      label.use :input, label: false                                                                                                                                                          
      label.use :label_text, wrap_with: { tag: "span", class: "label-text" }
    end    
  end                                                                                                                                                                                        
end

我正在尝试输出下面的 HTML 结构

<ul>
  <li>
    <label>
      <input type="radio"></input>
      <span></span>
    </label>
  </li>
</ul>

当前输出为:

<ul class="inline-list radio_buttons optional search_category">
  <li>
    <label class="faux-tab">
      <span class="radio">
        <input checked="checked" class="radio_buttons optional" id="search_category_" name="search[category]" type="radio" value="">
        <label class="collection_radio_buttons" for="search_category_">All</label>
      </span>
      <span class="label-text">Category</span>
    </label>
  </li>
</ul>
4

2 回答 2

1

它是simple_form.rb. 找到这一行,并确保 的boolean_style值为:inline

# Define the way to render check boxes / radio buttons with labels. # Defaults to :nested for bootstrap config. # inline: input + label # nested: label > input config.boolean_style = :inline

于 2016-03-10T13:57:57.270 回答
0

下面的代码可能会产生您预期的 HTML:

config.wrappers :category_tab, tag: "ul" do |ul|
  ul.use :html5
  ul.wrapper tag: "li" do |li|
    li.wrapper tag: "label" do |label|
      label.use :input, label: false 
    end    
  end
end
于 2014-03-11T11:09:22.000 回答