Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MohamedLamineAllal/233a71b40bfab673e8f4fa00d53f44ed to your computer and use it in GitHub Desktop.
Save MohamedLamineAllal/233a71b40bfab673e8f4fa00d53f44ed to your computer and use it in GitHub Desktop.
TypeHead and BloodHound automatic dataset update example
axios.get('/json/countries')
.then(function (resp) {
countriesCities = resp.data;
// alert(JSON.stringify(countriesCities['Afghanistan']));
cc_bloodHound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
reinitialize: true,
locale: null
});
cc_bloodHound.clear();
cc_bloodHound.add(countriesCities['Afghanistan']);
cityInput.typeahead({
highlight: true,
// hint: false,
autoSelect: true
}, {
name: 'city',
source: cc_bloodHound
});
// $('.typeahead').bind('typeahead:select', function (ev, suggestion) {
// console.log('Selection: ' + suggestion);
// console.log(ev);
// ev.target.blur();
// document.body.focus(true);
// addressLine1.get(0).focus(true);
// addressLine1.focus();
// console.log(addressLine1);
// });
})
.catch(function (err) {
alert('Err: ' + JSON.stringify(err))
})
countrySelect.on('change', function () {
// alert(ucwords(countrySelect.val()));
cc_bloodHound.clear();
cc_bloodHound.add(countriesCities[ucwords(countrySelect.val())]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment