简体   繁体   English

使用带引导程序3的simple_form

[英]using simple_form with bootstrap 3

Does anyone know how to change the class simple_form uses from 'controls' to 'form-control'. 有没有人知道如何将类simple_form从'controls'改为'form-control'。 This was a change made in Bootstrap 3. I know there are many options in config/initializers/simple_form.rb and config/initializers/simple_form_bootstrap.rb but I can't find what I need. 这是Bootstrap 3中的一个更改。我知道config / initializers / simple_form.rb和config / initializers / simple_form_bootstrap.rb中有很多选项,但我找不到我需要的东西。

  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_    class => 'error' do |b|
   b.use :html5
   b.use :placeholder
   b.use :label
   b.wrapper :tag => 'div', :class => 'controls' do |ba|
     ba.use :input
     ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
    ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
  end
end

in the above you can swap out 'control-group' for 'form-group', but I see no way to change the class for the input tag. 在上面你可以将'control-group'替换为'form-group',但我认为没有办法改变输入标签的类。

In newer simple_form versions, there is a new global config you can use: 在较新的simple_form版本中,您可以使用新的全局配置:

config.input_class = "form-control"

You need the gem version >3.0.0 which depends on rails >4.0.0, or the upcoming 2.2 release. 您需要gem版本> 3.0.0,这取决于rails> 4.0.0,或即将发布的2.2版本。 You can use the v2.2 branch on github for now. 您现在可以在github上使用v2.2分支。

See https://github.com/plataformatec/simple_form/blob/v2.2/CHANGELOG.md 请参阅https://github.com/plataformatec/simple_form/blob/v2.2/CHANGELOG.md

Why not just change the default wrapper in your simple_form_bootstrap.rb initializer? 为什么不直接更改simple_form_bootstrap.rb初始化程序中的默认包装器?

  config.wrappers :bootstrap, tag: :div, class: "form-group", error_class: "has-error" do |b|

    # Form extensions
    b.use :html5
    b.use :placeholder

    # Form components
    b.use :label
    b.wrapper tag: :div do |ba|
      ba.use :input
      ba.use :hint,  wrap_with: { tag: :p, class: "help-block" }
      ba.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
    end
  end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM