ruby - How can a dropdown be stylized when using twitter bootstrap with simple_form in a Rails app? -


i using simple_form , twitter-bootstrap-rails gems. every thing working fine somehow drop-down not getting stylized twitter bootstrap rails ..it shows normal forms.

<%= f.input :category, :collection => ["one", "two", "three", "four"],     :input_html => {:class => 'dropdown'}, :label => 'send to', prompt: "choose list" %> 

image of dropdown showing:

enter image description here

image of dropdown needed in bootstrap

enter image description here

one way stylized dropdowns simpleform , bootstrap use bootstrap-select. there rails gem it; add gemfile , bundle:

gem 'bootstrap-select-rails' 

you need add stylesheet

@import "bootstrap-select"; 

and javascript.

//= require bootstrap-select 

now, need use input_html: {class: 'selectpicker'} in existing f.input:

<%= f.input :category, :collection => ["one", "two", "three", "four"], :input_html => {:class => 'selectpicker'}, :label => 'send to', prompt: "choose list" %> 

and initialize javascript (which one-off regardless of how many selectpickers have):

<%= javascript_tag "$('.selectpicker').selectpicker();" %> 

restart app , input dropdown should render bootstrap styling.

some info may useful: can disable prompt item cannot selected dropdown adding disabled class item. couldn't find guidance on simpleform how apply style 1 element of collection came below such prompts:

<%= javascript_tag "$('li[data-original-index=0]').addclass('disabled');" %> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -