You can use Select2.js, it is a search component equal to the select you are using, but it makes calls to the server with ajax filtering by the value typed in it. I believe that’s what you need.
To use is very easy
Add these 2 files to the head of your website
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
and to use it just do the following:
Mount the html:
<select class="js-data-example-ajax">
<option value="3620194" selected="selected">select2/select2</option>
</select>
and create the javascript responsible for configuring the component:
$(".js-data-example-ajax").select2({
ajax: {
url: "https://api.github.com/search/repositories",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data.items
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
If you need more information just visit the official website:
https://select2.github.io/examples.html
Inside a select is not possible, but you can make your own select with other elements like
div
and then have more freedom to insert inputs.– Sergio
this is usually done by javascript where you only have to compose an array of valoires by default. when the list is small (up to about 200) use the typeahed, if you don’t want to check out this plugin: http://semantic-ui.com/modules/dropdown.html
– balexandre