We are trying re-implement our sign-up form with bootstrap. Our sign up form contains a drop-down list which represents a company type. I have searched extensively online but I do not see any example where a form input would be a drop down.
Bootstrap gives a ton of examples of drop-downs related to various action but what I need is a drop down input. I have come up with two solutions:
First:
<label>Type of Business</label>
<select class="form-control">
<option>small</option>
<option>medium</option>
<option>large</option>
</select>
There is a problem here: although the box itself is styled correctly the drop-down itself has no styles applied.
Second version:
<div class="btn-group">
<button type="button" class="form-control btn btn-default dropdown-toggle" data-toggle="dropdown">
Select Business type <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">small</a></li>
<li><a href="#">medium</a></li>
<li><a href="#">large</a></li>
</ul>
</div>
This one looks nice:
but it's a button. When an option is selected, I do not want to perform any action all I want is to change text and bind the selection with a corresponding input field.
Both of these approaches seams to be a wrong choice for my action. I refuse to believe that Bootstrap does not contain a simple drop-down single select component bound to an input field.
What am I missing ? Please help.
The dropdown list appearing like that depends on what your browser is, as it is not possible to style this away for some. It looks like yours is IE9, but would look quite different in Chrome.
You could look to use something like this:
http://silviomoreto.github.io/bootstrap-select/
Which will make your selectboxes more consistent cross browser.
Ive been looking for an nice select dropdown for some time now and I found a good one. So im just gonna leave it here. Its called bootsrap-select
here's the link. check it out. it has editable dropdowns, combo drop downs and more. And its a breeze to add to your project.
If the link dies just search for bootstrap-select by silviomoreto.github.io. This is better because its a normal select tag
I'd like to extend the paulalexandru's answer and put here complete solution that works generally with bootstrap dropdowns and updating main button's content and also the value from selected option.
The bootstrap dropdown is defined this way:
Additional to standard bootstrap dropdown code, there is
data-value
attribute for storing the values in every dropdown option (in<a>
element).Now the JS code. I crated function that handle the dropdowns:
And of course we need to add event listener:
You can also add 'active' class to the selected item.
See the jsfiddle example
We just switched our site to bootstrap 3 and we have a bunch of forms...wasn't fun but once you get the hang it's not too bad.
Is this what you are looking for? Demo Here