Skip to content

Instantly share code, notes, and snippets.

@ravindrabajpai
Forked from jharding/default-suggestions.html
Last active December 30, 2017 07:08
Show Gist options
  • Save ravindrabajpai/f55efbe80d6a3e8393dbd3d541760ad7 to your computer and use it in GitHub Desktop.
Save ravindrabajpai/f55efbe80d6a3e8393dbd3d541760ad7 to your computer and use it in GitHub Desktop.
<div id="default-suggestions">
<input class="typeahead" type="text" placeholder="NFL Teams">
</div>
var nflTeams = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('team'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function(obj) { return obj.team; },
prefetch: '../data/nfl.json'
});
function nflTeamsWithDefaults(q, sync) {
if (q === '') {
sync(nflTeams.get('Detroit Lions', 'Green Bay Packers', 'Chicago Bears', 'Real Madrid'));
}
else {
nflTeams.search(q, sync);
}
}
$('#default-suggestions .typeahead').typeahead({
minLength: 0,
highlight: true
},
{
name: 'nfl-teams',
display: 'team',
source: nflTeamsWithDefaults
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment