12

Does anyone know how to change the class simple_form uses from 'controls' to '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.

  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.

Harry Moreno
  • 10,231
  • 7
  • 64
  • 116

2 Answers2

15

In newer simple_form versions, there is a new global config you can use:

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. You can use the v2.2 branch on github for now.

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

helderdarocha
  • 23,209
  • 4
  • 50
  • 65
usha
  • 28,973
  • 5
  • 72
  • 93
0

Why not just change the default wrapper in your simple_form_bootstrap.rb initializer?

  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
mwalsher
  • 2,790
  • 2
  • 33
  • 41
  • btw they are now using the class "form-group" instead as in the code above... they changed it since beta – mwalsher Sep 04 '13 at 19:01