Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>formatItem</code> formats an item for display in the dropdown list, while <code>formatResult</code> formats the item for display in the inputbox once it is selected.</p> <p>By default, autocomplete expects to get data from the specified url formatted as: </p> <pre><code>foo|bar|baz|bing zaz|ding|blop|grok </code></pre> <p>where each line is a row of data; each row being the data that it passes to <code>formatItem</code> and <code>formatResult</code>. You may want to take the path of least resistance and return data in the way it likes.</p> <p>If you want to use data that doesn't fit autocomplete's assumptions, you'll need to use the (undocumented, as far as I can tell) parse option to identify a function to parse the results of your ajax request. It appears to me that your django view is returning an array rather than returning a formatted string. To format your array as jquery would like it:</p> <pre><code>return HttpResponse('|'.join(your_array), mimetype='text/plain') </code></pre> <p>Here is an example of doing autocomplete using non-standard autocomplete data (JSON):</p> <pre><code>&lt;script type="text/javascript"&gt; format_item = function (item, position, length){ return item.title; } // Handle data from ajax request prep_data = function(data){ tmp = $.evalJSON(data); parsed_data = []; for (i=0; i &lt; tmp.length; i++) { obj = tmp[i]; // Other internal autocomplete operations expect // the data to be split into associative arrays of this sort parsed_data[i] = { data: obj , value: obj.isbn13, result: obj.title }; } return parsed_data } $(document).ready(function(){ $("#fop").autocomplete({ url : "{% url book-search %}", // undocumented parse: prep_data, formatItem: format_item, }); }) &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload