Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap - dropdown with free text

I need to display a dropdown list on an html page. I would like that the user could also add free text inside the combobox if he doesnt't find the value he wants. Is it possible and not too much complicated? I have bootstrap and jquery. Thanks!

like image 768
user1820620 Avatar asked Dec 09 '14 09:12

user1820620


2 Answers

With a datalist that is pretty easy - no CSS/JavaScript required.

Here is a Bootstrap example:

<form role="form">
   <div class="form-group">
      <input type="text" class="form-control" list="select-list-id"/>
   </div>
   <datalist id="select-list-id">
      <option value="What was your childhood nickname?"></option>
      <option value="In what city did you meet your spouse/significant other?"></option>
   </datalist>
</form>

See fiddle.

like image 93
Martin Thoma Avatar answered Oct 20 '22 12:10

Martin Thoma


To get you started, here are two libraries that will help achieve what you want.

Select2 supports many features and allows the user to input text.

Another option is Selectize.js but I haven't tried it out myself.

Finally there is this project which also achieves your desired effect.

like image 21
U r s u s Avatar answered Oct 20 '22 10:10

U r s u s