Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

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 : <a>https://ibb.co/7jRQhJt</a>

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 :
<a>https://ibb.co/r3hSDyX</a>


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.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


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.



refered code number 2 is this one :
https://makitweb.com/demos/loading-data-remotely-in-select2-with-ajax


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(