I am using simple_form and twitter-bootstrap-rails gems. Every thing is working fine but somehow drop-down is not getting stylized by twitter bootstrap rails ..it shows like normal forms.
<%= f.input :category, :collection => ["one", "two", "three", "four"],
:input_html => {:class => 'dropdown'}, :label => 'Send To', prompt: "Choose From List" %>
IMAGE OF DROPDOWN SHOWING:
IMAGE OF DROPDOWN NEEDED AS IN BOOTSTRAP
Replace
With
.form-control
is used to style select tags. All textual<input>, <textarea>, and <select>
elements with.form-control
are set to width: 100%; by default. Wrap labels and controls in.form-group
for optimum spacing.dropdown
is not used forselect
tags. See details hereOne way to get stylized dropdowns with SimpleForm and Bootstrap is to use Bootstrap-Select. There is a Rails Gem for it; add to your Gemfile and do a
bundle
:You need to add it to your stylesheet
and Javascript.
Now, all you need to do is use
input_html: {class: 'selectpicker'}
in your existingf.input
:and then initialize the Javascript (which is a one-off regardless of how many selectpickers you have):
Restart your app and your input dropdown should render with Bootstrap styling.
Some extra info that may be useful: you can disable the prompt item so that it cannot be selected from the dropdown by adding the
disabled
class to the item. I couldn't find any guidance on SimpleForm how to apply a style to one element of a collection but I came up with the below that does it to all such prompts: