I've played around with every setting I can think of, e.g., .clear()
and .typeahead('destroy')
, and once I've set the source as remote I can't make the typeahead use a local source.
Any thoughts?
Here's the code below that gets called onclick
:
var create_typeahead = function(is_remote, titles){
filters_typeahead.typeahead('destroy');
if(is_remote){
var remote_url = titles;
var titles = new Bloodhound({
queryTokenizer: Bloodhound.tokenizers.whitespace,
datumTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: remote_url,
q=%QUERY',
wildcard: '%QUERY'
}
});
}
else{
var titles0 = titles;
var titles = new Bloodhound({
queryTokenizer: Bloodhound.tokenizers.whitespace,
datumTokenizer: Bloodhound.tokenizers.whitespace,
local: titles0
});
}
titles.initialize();
filters_typeahead.typeahead({
highlight: true,
minLength: 2,
},
{
name: 'titles',
displayKey: 'name',
source: titles,
templates: {
suggestion: function(data) {
return '<div>' + data.name + '</div>';
}
}
});
};