简单的形式和引导3

oli*_*art 0 simple-form ruby-on-rails-3.2

随着Bootstrap的最新更改,我想将常见的css类input_html: {class: 'form-control'}应用于所有元素,但不需要手动为所有元素执行.有没有办法默认设置它.我还没有找到任何设置.

mwa*_*her 7

你最好在app/config/initializers中更改simple_form_bootstrap.rb中的默认包装器.

例如:

SimpleForm.setup do |config|
  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|
    b.use :input
    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
    # end
  end

  config.form_class = "form-horizontal"
  config.default_wrapper = :bootstrap

end
Run Code Online (Sandbox Code Playgroud)