I\'m trying to make the jQuery UI autocomplete widget work with the Flask framework.
http://flask.pocoo.org/docs/patterns/jquery/
http://jqueryui.com/autocom
You have to wrap the $.getJSON()
in a function which will get executed by the plugin whenever the value of the textfield is changed
source: function( request, response ) {
$.getJSON($SCRIPT_ROOT + "/_search_university", {
search: request
}, response);
}
Now depending on what you are returning from the server, the above may suffice. However if you need to filter or map the data in order for autocomplete to display it you will need to use the $.map()
function to transform the data to a format acceptable by autocomplete
source: function( request, response ) {
$.getJSON($SCRIPT_ROOT + "/_search_university", {
search: request
}, function( data ) {
response( $.map( data.results, function( item ) {
return {
label: item.name,
value: item.id
}
}));
});
}
If you provide me, with the JSON that your server returns, I can be more specific
Check http://api.jqueryui.com/autocomplete/#option-source to see more information