Select2 Ajax support.
Hi keenthemes,
I create a backend API for a drug search checkup, and hook it with select2 and search using select2 Ajax options, everything works great, except when I seach and select in a drop down, it wont validated the result in the select2 input box = meaning nothing happend if you click on the dropdown selection.
here's the screenshots : https://ibb.co/7jRQhJt
refered to those online ressources :
1 - https://select2.org/data-sources/ajax
2 - https://makitweb.com/demos/make-a-dropdown-with-search-box-using-jquery
here's a result of an "pa" search result json api result format :
https://ibb.co/r3hSDyX
Here's my js :
$("#id_prescriptiondetail-0-drug").select2({
minimumInputLength: 2,
minimumResultsForSearch: 20,
//placeholder: "Select a state",
placeholder: {
id: '-1', // the value of the option
text: 'Search a drug'
},
allowClear: true,
cache: true,
ajax: {
url: "http://127.0.0.1:8000/api/drugs/",
type: "get",
dataType: 'json',
delay: 250,
data: function(params) {
return {
searchTerm: params.term // search term
};
},
processResults: function(response) {
return {
results: response
};
}
}
});
Can you please supply a Select2 Ajax capabilities in the next update, please.
thank you.
Replies (4)
refered code number 2 is this one :
https://makitweb.com/demos/loading-data-remotely-in-select2-with-ajax
Hi Keenthemes, forget about, I dropped the select2 ajax route (now).
went Tagify select mode route.
hope the ajax will be not that hard.
thank you.
Hi,
Noted, we will have a look at this. It is in our to-do list since your initial request.
Regards
Thank you Sean.