2013-07-15 44 views
0

有誰知道如何寫bootstrap-switchsimple_form包裝?用於自舉開關的導軌簡單形式包裝?

生成的HTML需要看起來像這樣:

<div class="control-group"> 
    <label class="control-label" for="inputEmail">Email</label> 
    <div class="controls"> 
     <input type="text" id="inputEmail" placeholder="Email"> 
    </div> 
</div> 
+0

你想使用包裝引導程序開關和生成的HTML。我發現[form-horizo​​ntal original bootstrap](http://twitter.github.io/bootstrap/base-css.html#form-horizo​​ntal)和[form-horizo​​ntal bootstrap switch](http:// www。 larentis.eu/switch/#form-horizo​​ntal) –

回答

-3

simple_form有內置自舉插件檢查出來here

+0

是的,我正在使用它,但我需要一個自舉開關的包裝。 – CoderDave

2

我不明白你將如何使用引導開關腳本的文本字段。儘管如此,有些人可能會在這裏以與標題中所提問題相同的問題結束。

您可以簡單地複製引導包裝,並添加所需的類:

config.wrappers :bootstrap_switch, tag: 'div', class: "control-group", error_class: 'error', boolean_style: :inline do |b| 
    b.use :html5 
    b.use :placeholder 
    b.use :label 
    b.wrapper tag: 'div', class: 'controls' do |ba| 
    ba.wrapper "switch", tag: 'div', class: 'switch' do |s| 
     s.use :input 
    end 
    ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } 
    ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } 
    end 
end 

這將創建一個具有一流的「開關」(因此由腳本風格化)嵌套式div。這個內部包裝有命名空間「開關」,它使我們能夠設置一些選項:

f.input :inputField, :wrapper => :bootstrap_switch, :switch_html => { :data => { on: "success", on_label: "<i class='icon-ok icon-white'></i>", off: "warning", off_label: "<i class='icon-remove'></i>" } }