Skip to content

Instantly share code, notes, and snippets.

@jharding
Last active May 15, 2024 16:16
Show Gist options
  • Save jharding/9458749 to your computer and use it in GitHub Desktop.
Save jharding/9458749 to your computer and use it in GitHub Desktop.
<div id="bloodhound">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
// constructs the suggestion engine
var states = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// `states` is an array of state names defined in "The Basics"
local: states
});
$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: states
});
@ulvido
Copy link

ulvido commented Jul 21, 2017

for the newbeies like me; to make bloodhound work standalone...

$(document).ready(function() {

/ / add states var here (search data)
var states = ['Alabama', 'Chicago',etc ]

// constructs the suggestion engine
var states = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// states is an array of state names defined in "The Basics"
local: states
});

$('#bloodhound .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: states
});
});

@niketpathak
Copy link

niketpathak commented May 24, 2018

A nice article based on a maintained fork(v1.2.1) since the original project has been abandoned since 3+ years (Ref)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment