Created
November 27, 2018 09:51
-
-
Save MohamedLamineAllal/233a71b40bfab673e8f4fa00d53f44ed to your computer and use it in GitHub Desktop.
TypeHead and BloodHound automatic dataset update example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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