2013-08-24 68 views
0

隨着對Bootstrap的最新變化,我想將普通的css類input_html: {class: 'form-control'}應用於所有元素,但沒有手動完成所有元素。有沒有什麼辦法可以讓它默認。我還沒有找到任何設置。簡單的形式和引導3

回答

-2

jQuery的可能是實現這一目標的亞倫龔提到的一種方式。它會爲您節省手動操作的時間,但實際上在客戶端添加了一個虛擬步驟,這可能不是最乾淨的解決方案。

您也可以嘗試使用css選擇器應用sass @extend(http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#extend)來選擇要修改的輸入類型。

input[type='email'], input[type='password'] { 
     @extend .form-control; 
    } 
+0

你最好不要更改默認的包裝中的應用程序/配置/初始化simple_form_bootstrap.rb。 – mwalsher

0

使用jQuery(但*所有元素可以招致一些性能問題)

$('*').addClass('form-control'); 

希望它可以幫助...

7

你最好不要更改默認的包裝中的應用程序/配置/初始化simple_form_bootstrap.rb。

E.g:

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 
0

內初始化使用簡單:

SimpleForm.setup do |config| 
    config.label_class = 'control-label' 
    ... 
end