I'm using typeahead (0.10.1) in an app to return a list of clients using bloodhound prefetch. I can't work out how to update/reinitialise bloodhound with a new thumbprint so that after the new client is inserted it will use a new thumbprint and hence include the new client.
The system is ajax so I can't just change the name on refresh, I'm trying to pass it another thumbprint as per below in the reinitializeclient() but it's not working:
var clientthumbprint = "initialname";
var clients = new Bloodhound({
limit: 5,
prefetch:{
url: '/urltofeed/',
thumbprint:getthumbprint()
},
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.label);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
clients.initialize();
function reinitializeclient(newthumbprint){
//This is called when a client is saved
clientthumbprint = newthumprint;
clients.initialize(); //this didn't work
}
function getthumbprint(){
return clientthumbprint;
}
$('#search_user').typeahead({
minLength: 2,
},
{
displayKey: 'label',
source: clients.ttAdapter()
})
Anyone have any ideas what I'm doing wrong?
EDIT: After updating my typeahead files using the pull request mentioned by @jharding, I can get it to reset, but not reinitialise.Using the following:
function initialize_clients(){
clients = new Bloodhound({
limit: 5,
prefetch:{
url: '/pathtojson/',
thumbprint:getthumbprint()
},
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.label);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
clients.initialize();
};
function resetclients(){
clientthumbprint = 'somenewthumbprint';
clients.reset();//this works - after running nothing will return in search
initialize_clients();//this is not working
}
function getthumbprint(){
return clientthumbprint;
}