【问题标题】:using simple_form with bootstrap 3在 bootstrap 3 中使用 simple_form
【发布时间】:2013-08-23 12:51:43
【问题描述】:

有谁知道如何将 simple_form 使用的类从“控件”更改为“表单控件”。这是在 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

在上面你可以将'control-group'换成'form-group',但是我看不出有办法改变输入标签的类。

【问题讨论】:

  • 你试过ba.use :input, :wrap_with => { :class => 'form-control' }吗?
  • 是的,将给定的类应用于包装 元素的 div
  • config.input_class = 'form-control' 输入的默认类

标签: ruby-on-rails twitter-bootstrap simple-form twitter-bootstrap-3


【解决方案1】:

在较新的 simple_form 版本中,您可以使用一个新的全局配置:

config.input_class = "form-control"

您需要 gem 版本 >3.0.0,它依赖于 rails >4.0.0,或即将发布的 2.2 版本。你现在可以使用 github 上的 v2.2 分支。

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

【讨论】:

  • 我没有看到这一点,因为我没有运行最新的 simpleform 测试版。现在我必须更新到 rails 4 并更新 simpleform 并移动到 bootstrap 3。哈哈
  • 关于如何修复有问题的复选框输入的任何想法?
  • config.input_class 不再受支持。
  • 我可以确认,这似乎不再有效。 Rails 4.2.0 和 simple_form 3.1.0 不适合我。 :(
【解决方案2】:

为什么不直接更改 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

【讨论】:

  • 顺便说一句,他们现在正在使用类“form-group”而不是像上面的代码中那样......他们从 beta 版开始改变了它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-04
  • 1970-01-01
相关资源
最近更新 更多