【问题标题】:simple_form boostrap form-horizontal initializer wrappers aren't applied未应用 simple_form bootstrap form-horizo​​ntal initializer 包装器
【发布时间】:2015-07-24 18:29:00
【问题描述】:

所以我使用bootstrap-sasssimple_form gem 并使用--boostrap 运行安装程序,这意味着它在config/initializers/ 目录中生成了simple_form_bootstrap.rb

我正在尝试使用引导程序中的 form-horizontal 类,但这需要将 input 包装为具有 col-xx-xx 类的 div

我查看了上述初始化程序并看到了这个块:

 config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.optional :maxlength
    b.optional :pattern
    b.optional :min_max
    b.optional :readonly
    b.use :label, class: 'col-sm-3 control-label'

    b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
      ba.use :input, class: 'form-control'
      ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
      ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
    end
  end

看起来初始化程序已经将正确的类应用于标签并将输入标签包装在一个 div 中。然而,这种情况并非如此。初始化器有错误吗?

以下是表格供参考:

<%= simple_form_for @article, remote: true, html: {class: "form-horizontal"} do |f| %>
        <ul class="errors"></ul>
            <%= f.input :author%>
            <%= f.input :title%>
            <%= f.button :submit, class: "btn btn-primary" %>
<% end %>

这是对应的html:

<div class="form-group string optional article_author">
  <label class="string optional control-label" for="article_author">...</label>
  <input id="article_author" class="string optional form-control" type=".." name=".." value="..." style="..."></input>
</div>

所以看起来初始化程序中的一些东西像类表单控件一样被添加,但不是其余的。为什么?

【问题讨论】:

    标签: html css ruby-on-rails twitter-bootstrap simple-form


    【解决方案1】:

    因此,您需要在 form_for 标记中使用 wrapper: "form_horizontal" 来应用包装器。这将使用该名称的所有初始化程序。

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 2012-11-15
      相关资源
      最近更新 更多