I successfully integrated the world countries list from https://github.com/stefangabos/world_countries into select2 to display all countries. Does anyone have any insights on how to enable searching within the listed countries?
var countriesList = 'https://cdn.jsdelivr.net/npm/world_countries_lists@latest/data/en/countries.json';
$('select').select2({
ajax: {
url: countriesList,
dataType: 'json',
delay: 250,
data: function (params) {
console.log(params.term);
return {
q: params.term
};
},
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
id: item.id,
text: item.name
};
})
};
}
},
width: 300,
dropdownAutoWidth: true
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4c5a535a5c4b0d7f0b110e110f125d5a4b5e110e">[email protected]</a>/dist/js/select2.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d4e5851585e490f7d09130c130d105f58495c130c">[email protected]</a>/dist/css/select2.min.css" rel="stylesheet"/>
<select></select>