'Select2.Js Doesn't Show Dropdown Without Entering Values In Text Filed
I used Select2.Js for dropdown menu. But the value isn't show in Dropdown without entering one value or word. Everytime I have to insert one word to get results.
I tried to make minimumInputLength: 0 But doesn't work. I need only Simple Dropdown Menu.
Here is My Code
$("#stores").select2({
ajax: {
url: storeSearchUrl,
dataType: 'json',
type: 'POST',
data: function (params) {
return {
searchText: params.term
};
},
processResults: function (data, params) {
if (data.redirect) {
window.location.href = data.redirect;
} else {
if (data.error) {
app.notification('error', data.error);
} else {
return {
results: $.map(data, function (item) {
if(labaccess != null && labaccess != "" && labaccess != "[]"){
if(labaccess.includes(item.id)){
return {
text: item.name,
id: item.id,
term: params.term
}
}
}
else{
return {
text: item.name,
id: item.id,
term: params.term
}
}
})
};
}
}
},
cache: false
},
templateResult: function (item) {
if (item.loading) {
return item.text;
}
return app.markMatch(item.text, item.term);
},
minimumInputLength: 0
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

