Questions tagged [typeahead.js]

typeahead.js is a JavaScript library written by Twitter for computing and displaying suggestions as the user types - for instance, to implement autocomplete functionality

Documentation can be found at https://github.com/twitter/typeahead.js/. typeahead.js has two main components, Typeahead and Bloodhound, whose docs can be found at https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md and https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md respectively.

Note: this project is currently not maintained. A maintained fork can be found at: https://github.com/corejavascript/typeahead.js

Stack Snippet Starter Pack

HTML

<link href="http://twitter.github.io/typeahead.js/css/examples.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.js"></script>

<input class="typeahead" type="text" placeholder="States of USA">

JavaScript

// some data to work with
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
  'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
  'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
  'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
  'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
  'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
  'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
  'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];

// constructs the suggestion engine
var states = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: states
});


// initialize typeahead by passing in options and data
$('.typeahead').typeahead({
  hint: true,
  highlight: true,
  minLength: 1
}, 
{
  name: 'states',
  source: states
});
1283 questions
284
votes
16 answers

twitter bootstrap typeahead ajax example

I'm trying to find a working example of the twitter bootstrap typeahead element that will make an ajax call to populate it's dropdown. I have an existing working jquery autocomplete example which defines the ajax url to and how to process the…
185
votes
10 answers

Twitter's typeahead.js suggestions are not styled (have no border, transparent background, etc.)

I'm using twitter's typeahead.js 0.9.3 and it seems my suggestions are not styled at all. I'm getting this: Instead of something like this: (taken from examples page) JavaScript enabling typeahead: $('.search-typeahead').typeahead({ name:…
Zugwalt
  • 19,935
  • 20
  • 77
  • 99
59
votes
14 answers

CSS issue on Twitter Typeahead with Bootstrap 3

With the release of Bootstrap 3. Typeahead has been removed in favor of this: https://github.com/twitter/typeahead.js Ive integrated it successfully on remote fetching of data but Im having problem with the autocompletion as you can see there are…
Jaime Sangcap
  • 2,175
  • 4
  • 23
  • 42
46
votes
10 answers

Twitter Bootstrap Typeahead - Id & Label

I'm using Bootstrap 2.1.1 and jQuery 1.8.1 and trying to use Typeahead's functionality. I try to display a label and use an id like a standard