Reputation: 25472
Am using JQuery Autocomplete on my templete, but as i get the results the Autocomplete only displays one item despite that the results that are fetched have more that one item. It only shows the first item on the list!
Example:
if i have a result list with ('python', 'pythonism', 'pythodus')
and on the autocomplete i type 'pyt' it only displays 'python' on the drop down!
My autocomplete code:
$(document).ready(function(){
$("#tags1").autocomplete("/taglookup/", {
width: 320,
max: 4,
highlight: false,
multiple: true,
multipleSeparator:",",
scroll: true,
scrollHeight: 300,
delay: 10
});
});
my AJAX django view that gets called:
def tag_lookup(request):
# Default return list
results = []
if request.method == "GET":
if request.GET.has_key(u'q'):
value = request.GET[u'q']
# Ignore queries shorter than length 3
if len(value) > 2:
TI = Tag.objects.filter(name__contains=value)
print TI
results = [ x.name for x in TI]
print results #shows me more than one item is returned
return HttpResponse('|'.join(results), mimetype='text/plain')
Upvotes: 0
Views: 1397
Reputation: 25472
Guys, just discovered that the JQuery Autocomplete plugin am using requires a new line character as a separator between items, so i have replaced my Ajax Django view to read like this;
return HttpResponse('\n'.join(results), mimetype='text/plain')
its working perfect!
Thanks.
Upvotes: 2
Reputation: 190945
It looks like the HttpResponse
is doing Something|Something|...
where the jQuery is wanting Something,Something,...
. Try changing multipleSeparator
to '|'
. Also, since I don't know the use of the print before the HttpResponse
.
Upvotes: 0