ruby-on-rails - 简单表格 : How can I create a custom wrapper that does not wrap the input and create a label?

标签 ruby-on-rails ruby-on-rails-3 simple-form

在 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>

最佳答案

这是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

关于ruby-on-rails - 简单表格 : How can I create a custom wrapper that does not wrap the input and create a label?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18384796/

相关文章:

ruby-on-rails - simple_form 中的封装映射

ruby-on-rails - 使用 Rails 导入 gmail/yahoo/hotmail/aol 地址簿

ruby-on-rails - rails : Have initializer load before application. rb

ruby-on-rails - Rails 模型验证条件 allow_nil?

ruby-on-rails - 如何在Ruby on Rails上下载YouTube视频

ruby-on-rails-3 - 轨道 3 中的观察字段

javascript - 使用 Java 脚本显示/隐藏输入字段的简单表单无法在显示和隐藏之间正确切换

ruby-on-rails - 如何告诉乘客使用另一个用户而不是 www-data?

ruby-on-rails - Postgresql 上带有 UUID 的 Rails 5.2 ActiveStorage

ruby-on-rails - simple_forms 自定义数据属性