The select2 feature is functioning almost as desired. It successfully loads all remote data and formats it correctly when another field is changed. However, I am looking to reintroduce the search function for the retrieved data. Specifically, once the data is fetched, I want users to be able to search the list by title (result.title).
In the provided example, the data is retrieved but the search term is not being filtered. It is crucial that all remote data be loaded before requiring users to search for a result.
If it is not possible to enable searching, how can I disable the search box? Even when setting "minimumResultsForSearch: -1", the select2 box still allows me to search?
https://i.sstatic.net/OwOv8.png
var $company2 = $(".company2");
$company2.select2().on('change', function() {
if ($company2.val() !== null) {
$('.unmaintained2').select2({
allowClear: true,
minimumResultsForSearch: 1,
ajax: {
url: "/api/unmaintained2/" + $company2.val(),
processResults: function (data) {
return {
results: data,
};
},
dataType: 'json',
cache: true,
},
escapeMarkup: function(m) {
return m;
},
templateResult: function (result) {
if (result.loading) return 'Loading...';
return result.text + '<h6>' + result.make + ' ' + result.category + '</h6>';
},
});
};
});