Issues with AJAX and noResults

352 views
Skip to first unread message

rebecca.l...@gmail.com

unread,
Jun 16, 2015, 12:42:54 PM6/16/15
to sel...@googlegroups.com
I have no idea what is wrong, and I can't find an answer anywhere:

The following works great, IF there are results:

jQuery("#last_name").select2({
ajax: {
url: "suggestions/",
dataType: 'json',
delay: 25,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, page) {
return {
results: data.items
};
},
cache: false
},
language: {
noResults: function() {
return "No Results";
}
}
});

But if there are no results, then it's not doing what one would expect -- it just highlights the typed in term, with no "No Results" message.

Maybe I've got the ajax formatted wrong for zero results? It's currently showing:

{"items": []}

Any help is appreciated; I'm desperate to get this finished.

Kevin Brown

unread,
Jun 19, 2015, 6:43:53 PM6/19/15
to sel...@googlegroups.com
It sounds like you are using the `tags` option which will allow the user to always add new options based on what they have typed in to search.

I can't reproduce the issue you are seeing without the tags option, Select2 displays the no results found message. You should be able to reproduce it on the Select2 examples with GitHub's API: https://select2.github.io/examples.html#data-ajax

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

thasn...@gmail.com

unread,
Jan 7, 2020, 9:36:38 PM1/7/20
to select2
Yes. AS @kevin said, if remove 
tags: true

It works well.

Thanks @kevin
Reply all
Reply to author
Forward
0 new messages