Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Dropdown with search box in it

Tags:

I want to add search box to a single select drop down option.

Code:

<select id="widget_for" name="{{widget_for}}">
<option value="">select</option>

{% for key, value in dr.items %}

<input placeholder="This ">

<option value="{% firstof value.id key %}" {% if key in selected_value %}selected{% endif %}>{% firstof value.name value %}</option>


{% endfor %}
</select>

Adding a input tags as above does not work out.

I have tried using html5-datalist and it works. I want some other options as html5-datalist does not support scrollable option in chrome.

Can anyone suggest any other searchbox options? They should be compatible with django-python framework.

like image 608
s_user Avatar asked Apr 19 '16 08:04

s_user


Video Answer


2 Answers

There's also a plain HTML solution You can use a datalist element to display suggestions:

<div>
    <datalist id="suggestions">
        <option>First option</option>
        <option>Second Option</option>
    </datalist>
    <input  autoComplete="on" list="suggestions"/> 
</div>

Note:Ensure that value of list attribute in input is same as the id of datalist.

Please be advised not all broswers have (full) support for the Datalist Element, as you can see on Can I use.

like image 167
Fahad Israr Avatar answered Oct 16 '22 07:10

Fahad Israr


Simply use select2 plugin to implement this feature

Plugin link: Select2

enter image description here

like image 27
Deepak Avatar answered Oct 16 '22 06:10

Deepak