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.
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.
Simply use select2 plugin to implement this feature
Plugin link: Select2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With