簡體   English   中英

使用帶引導程序3的simple_form

[英]using simple_form with bootstrap 3

有沒有人知道如何將類simple_form從'controls'改為'form-control'。 這是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',但我認為沒有辦法改變輸入標簽的類。

在較新的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

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