views:

447

answers:

2

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')
A: 

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.

Daniel A. White
If i replace "|" with "," nothing get displayed even the one item.
gath
+2  A: 

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.

gath
Answered your own question. +1
Jose Basilio