I am new to Select2 and am having trouble integrating AJAX. When I search, the results aren't being filtered based on the query.
Here's how it looks: https://i.sstatic.net/Q8mjM.png - The right characters are underlined in the results, but nothing is filtered out. In my non-ajax Select2 and in the examples I've seen, the filtering seems to happen somewhat automatically, so I am hesitant to write a custom filter as there is probably a better one built in already.
Here's my code:
<script>
$("#search_bar").select2({
placeholder: "Search for another Concept",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "/concepts/names_for_search",
dataType: 'json',
data: function (term, page) {
return {
q: term, // search term
page: page
};
},
results: function (data, page) {
return { results: data};
}
},
});
</script>
Also, here is an example of my JSON:
[{"id":1,"text":"Limits"},{"id":2,"text":"Derivatives"},{"id":3,"text":"One-Sided Limits"},{"id":4,"text":"Formal Definition of a limit"}]
Any ideas? Hopefully I am just doing something stupid and it is a quick fix. Thanks in advance for any help.