typeahead.js is a fast and fully-featured autocomplete library

Overview

build status Built with Grunt

typeahead.js

Inspired by twitter.com's autocomplete search functionality, typeahead.js is a flexible JavaScript library that provides a strong foundation for building robust typeaheads.

The typeahead.js library consists of 2 components: the suggestion engine, Bloodhound, and the UI view, Typeahead. The suggestion engine is responsible for computing suggestions for a given query. The UI view is responsible for rendering suggestions and handling DOM interactions. Both components can be used separately, but when used together, they can provide a rich typeahead experience.

Getting Started

How you acquire typeahead.js is up to you.

Preferred method:

  • Install with Bower: $ bower install typeahead.js

Other methods:

Note: both bloodhound.js and typeahead.jquery.js have a dependency on jQuery 1.9+.

Documentation

Examples

For some working examples of typeahead.js, visit the examples page.

Browser Support

  • Chrome
  • Firefox 3.5+
  • Safari 4+
  • Internet Explorer 8+
  • Opera 11+

NOTE: typeahead.js is not tested on mobile browsers.

Customer Support

For general questions about typeahead.js, tweet at @typeahead.

For technical questions, you should post a question on Stack Overflow and tag it with typeahead.js.

Issues

Discovered a bug? Please create an issue here on GitHub!

https://github.com/twitter/typeahead.js/issues

Versioning

For transparency and insight into our release cycle, releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

Testing

Tests are written using Jasmine and ran with Karma. To run the test suite with PhantomJS, run $ npm test.

Developers

If you plan on contributing to typeahead.js, be sure to read the contributing guidelines. A good starting place for new contributors are issues labeled with entry-level. Entry-level issues tend to require minor changes and provide developers a chance to get more familiar with typeahead.js before taking on more challenging work.

In order to build and test typeahead.js, you'll need to install its dev dependencies ($ npm install) and have grunt-cli installed ($ npm install -g grunt-cli). Below is an overview of the available Grunt tasks that'll be useful in development.

  • grunt build – Builds typeahead.js from source.
  • grunt lint – Runs source and test files through JSHint.
  • grunt watch – Rebuilds typeahead.js whenever a source file is modified.
  • grunt server – Serves files from the root of typeahead.js on localhost:8888. Useful for using test/playground.html for debugging/testing.
  • grunt dev – Runs grunt watch and grunt server in parallel.

Maintainers

Authors

License

Copyright 2013 Twitter, Inc.

Licensed under the MIT License

Comments
  • Option for Automatic selection of the first item in the typeahead resultset

    Option for Automatic selection of the first item in the typeahead resultset

    Would it be possible for there to be an option for the first item to be automatically selected in the typeahead on search so a press of the enter key will go to that specific item's url? This would save the user needing to press the downarrow key to get to that first item and then pressing the enter key. Thanks!

    opened by RoyLee 51
  • Showing default suggestions on focus if minLength is 0

    Showing default suggestions on focus if minLength is 0

    This addresses https://github.com/twitter/typeahead.js/issues/62 -- letting you display some suggestions when the user has an empty search query. This behaviour is triggered by setting minLength to 0 for a dataset. This behaviour is especially useful to make a combo-box type input, and for smaller datasets.

    Default suggestions only work if dataset has local or prefetched data, and an error is thrown if you try to set minLength to 0 for a remote-only data source.

    By default, the order of the default suggestions is the same as the order the data is added. There could in theory be some inconsistencies in this ordering due to object key ordering not always being preserved, however these issues arise when mixing numeric and string keys, which will not be the case. My first version was actually storing this default ordering separately in local storage along with the data, but it seemed unnecessary.

    There is also an option to define a sort function that will be used by javascript's built in Array.sort function. For example, to sort alphabetically:

    $('#country-typeahead').typeahead([{
      name: 'countries',
      prefetch: '/api/countries.json',
      minLength: 0,
      defaultSort: function(a,b){ return a.value > b.value ? 1 : -1; }
    }])
    

    I opted to make the user add the .value in their function in case they want to sort by a custom property in their datums.

    opened by theoephraim 43
  • Example of typeahead:selected event

    Example of typeahead:selected event

    For anyone interested until an example is added to documentation for custom events...

    Assuming there's an input on your page called 'search_input':

    
    $('#search_input').bind('typeahead:selected', function(obj, datum, name) {      
            alert(JSON.stringify(obj)); // object
            // outputs, e.g., {"type":"typeahead:selected","timeStamp":1371822938628,"jQuery19105037956037711017":true,"isTrigger":true,"namespace":"","namespace_re":null,"target":{"jQuery19105037956037711017":46},"delegateTarget":{"jQuery19105037956037711017":46},"currentTarget":
            alert(JSON.stringify(datum)); // contains datum value, tokens and custom fields
            // outputs, e.g., {"redirect_url":"http://localhost/test/topic/test_topic","image_url":"http://localhost/test/upload/images/t_FWnYhhqd.jpg","description":"A test description","value":"A test value","tokens":["A","test","value"]}
            // in this case I created custom fields called 'redirect_url', 'image_url', 'description'   
    
            alert(JSON.stringify(name)); // contains dataset name
            // outputs, e.g., "my_dataset"
    
    });
    

    https://github.com/twitter/typeahead.js#custom-events

    opened by andy3rdworld 41
  • Custom event suggestions

    Custom event suggestions

    I was pretty conservative with what custom events I added in v0.9.0, now it's time to get a little crazier. Below is a combination of events I think would be nice to have and some events I've seen people asking for:

    • autocompleted – when the user tabs to select the suggestion the hint is showing.
    • rendered – suggestions for a given query were retrieved and rendered.
    • prefetch failed – requesting or processing the prefetched data fails for whatever reason.
    • nothing left – no suggestions were found for a given query.
    • suggestion highlighted – the user mouses or keys over a suggestion in the dropdown menu.
    • changed – emulate the native change event of an input element.

    I'm not sure implementing all of these is plausible, but I at least wanted to document them so a discussion could be had.

    Any other custom events you'd like to see implemented?

    opened by jharding 39
  • Show a spinner in the meantime the client is waiting for the results.

    Show a spinner in the meantime the client is waiting for the results.

    First off, thanks for this library, it's just great.

    I wonder whether it's possible to catch an event to show a spinner or something or the screen in the meantime the browser is waiting for the server to reply.

    Thanks!

    opened by loalf 35
  • Trigger custom events

    Trigger custom events

    There's a handful of issues asking for something along the lines of a "selection callback". While I agree this is necessary, I don't think adding an option like onSelection is the best way to go about it. Instead, I think triggering custom events on the typeahead input is the way to go. It's a more extensible approach and it won't pollute the options hash.

    I'm creating this ticket to start brainstorming what events we need to trigger. The only 2 I can think of right now are:

    • suggestion selected (#22)
    • prefetched data loaded (#64)

    If there's anything else you'd like an event triggered for, leave a comment in this issue.

    opened by jharding 33
  • Dropdown closes and reopens on keypress with remote dataset

    Dropdown closes and reopens on keypress with remote dataset

    You can see this with the best pictures example here

    Start typing 'broadway' (pre 1960 example that is not prefetched). At 'bro' it will be isolated from prefetched data. then each additional letter ('a', 'd', ...) will close + reopen dropdown with same value.

    bug typeahead-jquery 
    opened by ndreckshage 32
  • Method to clear dataset cache or make it context configurable (page or DOM element)

    Method to clear dataset cache or make it context configurable (page or DOM element)

    A method for clearing the dataset cache or changing its context from page level to element level would be useful. For larger/long running applications, the page-level cache behavior can be unexpected and undesirable. Providing away to override this, or at least programmatically clear the cache on demand would be helpful. For more justification please see my comment at the bottom of issue #41.

    opened by jeffmax 28
  • Request: publish typeahead and bloodhound on npm

    Request: publish typeahead and bloodhound on npm

    In the era of browserify and commonJS it makes sense to publish also front-end-only packages on npm.

    • npm stores the tagged versions on it's own servers
    • when managing dependencies, i'd rather manage them all in npm (most of the dependencies I use are already on npm)
    • it's nice to have the option, isn't it?
    opened by ragulka 27
  • Using

    Using "open" on clicking the input

    Hello,

    I'm not sure how the .typehead("open") works. My minLength setting is set to 0. What I want is to make the dropdown appear (especially when empty) without typing anything not only when the input is focused and I push up/down arrows but also when I click the input with mouse. I created a simple fiddle to illustrate what my goal is: http://jsfiddle.net/YxmF2/. When you click on the input, you should get the dropdown appear.

    If this is intented to be like this, then what's the purpose of .typeahead("open") ? And if so, is there a way to do what I want to do?

    opened by patrykbuzowicz 25
  • event to tell when user typed their own value vs selecting a suggestion

    event to tell when user typed their own value vs selecting a suggestion

    Is there a way to get an event when the user "selects" the text that they have typed out, which is separate from the offered suggestions? I.e. user has typed 'apple', with provided suggestion 'applesauce'; however user really wants to submit simply 'apple'.

    Originally I tried using the 'change' event for this:

        }).on('typeahead:selected', function($e, datum) {  // suggestion selected
              console.log('selected: ' + datum['url']);
              window.location = datum['url'];
        }).on('change', function(e) {                     // user typed their own value
              value = $('input.search-input').val();
              window.location = '/search_path?search=' + encodeURIComponent(value);
        });
    

    but unfortunately 'change' also seems to fire when the user selects from the drop-down, so if the user types 'apple' and then clicks 'applesauce' there's a kind of race condition where sometimes the form submits 'apple' and sometimes 'applesauce', depending on the speed of the remote.

    select 
    opened by armhold 23
  • 404 Search Issue (Heroku)

    404 Search Issue (Heroku)

    Describe the bug Search is returning a 404 due to proxy heroku site https://typeahead-js-twitter-api-proxy.herokuapp.com/demo/search?q= currently down

    To Reproduce Steps to reproduce the behavior:

    1. Search for any account
    2. See error

    Expected behavior Fetch call should return 200 and search results should load

    opened by maryamtb 0
  • A way to get the name of the data set while using multiple data sets

    A way to get the name of the data set while using multiple data sets

    Hello, is it possible to get the name of the data set when using multiple data sets? I want to do something different on select based on which data is being used. Below is my typeahead code, the data is being sent through json using bloodhound.

    For instance if it's coming from the providers I want it to return the "name" providers

    Thank you!

    $('.n-search-all').typeahead({ highlight: true }, { name: 'providers', display: 'text', source: nSearchProviders, templates: { header: '<h3 class="n-search-cat-name">Providers</h3>' } }, { name: 'locations', display: 'text', source: nSearchLocations, templates: { header: '<h3 class="n-search-cat-name">Locations</h3>' } }, { name: 'services', display: 'text', source: nSearchServices, templates: { header: '<h3 class="n-search-cat-name">Services</h3>' } });

    opened by anthonysbrown 0
  • Bloodhound matching not working with parenthesis and remote.

    Bloodhound matching not working with parenthesis and remote.

    I am searching string but not showing string with parenthesis. I used remote properties.

    var setting_info = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('search_name'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { ttl: 1, url: "{{ route('setting_info',[app()->getLocale()]) }}?query=%QUERY", wildcard: '%QUERY', } });

    Please help me. how to load string + parenthesis + remote combination?

    opened by Rakesh2907 0
  • Unclear duplication (in the form of plain text) on input

    Unclear duplication (in the form of plain text) on input

    Why is it that every time I finish typing in tagsinput (focus out of the text area), duplicates always appear in plain text on the form as shown in the image/video below.

    https://user-images.githubusercontent.com/49072140/178454846-8b70f501-f953-430b-8783-d91c70b84407.mov

    opened by ahmadkeren 0
  • Suggestions not showing inside Table Row

    Suggestions not showing inside Table Row

    Describe the bug Suggestions not showing inside Table Row

    As you can see in the below screenshot whenever I click on Add Dependents it would dynamically add a table row as shown in the screenshot. Inside the screenshot you can also see that when I type A the console does output 4 suggestions but it is not being displayed or rendered in the browser. Screen Shot 2022-05-05 at 8 23 58 PM

    Moreover when the user taps Add Dependents this is the code which gets called.

    var i = 0;
    $("#add-dependent-button").click(function (e) {
        document.getElementById("dependentTable").style.display="block";
        ++i;
        $("#dynamicAddRemove").append('<tr><td><input class="typeahead2 form-control" type="text" name="dependents[' + i +
            '][client_id]" placeholder="Start typing name..." required"/></td><td><select class="form-control" id="relationship" name="dependents['+i+'][relationship]">@foreach($relationships as $relationship)<option value="{{$relationship->id}}">{{$relationship->relation}}</option>@endforeach</select></td><td><button type="button" class="btn btn-outline-danger remove-input-field">Remove</button></td></tr>'
        );
        $('input.typeahead2').typeahead({
            source:  function (query, process) {
                console.log(`${query}`);
                return $.get(path, { query: query }, function (data) {
                    console.log(`${data}`);
                    return process(data);
                });
            }
        });
        e.preventDefault();
    });
    

    I am using bootstrap and Laravel.

    Appreciate your help!

    opened by utsavDave97 0
Owner
Twitter
Twitter 💙 #opensource
Twitter
Add Github like mentions autocomplete to your application.

⚠️ Announcement ⚠️ This project was no longer maintained. You could use zurb tribute instead. An autocompletion library to autocomplete mentions, smil

Harold.Luo 5.3k Dec 19, 2022
Ultra lightweight, usable, beautiful autocomplete with zero dependencies.

Awesomplete https://leaverou.github.io/awesomplete/ Awesomplete is an ultra lightweight, customizable, simple autocomplete widget with zero dependenci

Lea Verou 6.9k Jan 2, 2023
Automatically persist your forms' text and select field values locally, until the form is submitted.

Garlic.js Garlic.js allows you to automatically persist your forms' text and select field values locally, until the form is submitted. This way, your

Guillaume Potier 2.4k Dec 21, 2022
Add live paragraph-, word- and character-counting to an HTML element.

Countable Countable is a JavaScript function to add live paragraph-, word- and character-counting to an HTML element. Countable is a zero-dependency l

Sacha Schmid 1.6k Dec 2, 2022
jQuery plugin for styling checkboxes and radio-buttons

English description | Описание на русском jQuery-plugin for styling checkboxes and radio-buttons. With skin support. Version: 2.0.0 Project page and d

Denis Ineshin 70 Sep 24, 2022
A set of flat and 3D progress button styles where the button itself serves as a progress indicator

A set of flat and 3D progress button styles where the button itself serves as a progress indicator. 3D styles are used for showing the progress indication on one side of the button while rotating the button in perspective.

Codrops 608 Oct 19, 2022
typeahead.js is a fast and fully-featured autocomplete library

typeahead.js Inspired by twitter.com's autocomplete search functionality, typeahead.js is a flexible JavaScript library that provides a strong foundat

Twitter 16.5k Jan 4, 2023
autocomplete/typeahead js plugin for bootstrap v5

bootstrap-5-autocomplete This is a rewrite of https://github.com/Honatas/bootstrap-4-autocomplete for bootstrap v5. Example const ac = new Autocomplet

Evgeny Zinoviev 76 Dec 28, 2022
🔮 Fast and full-featured autocomplete library

Autocomplete A JavaScript library that lets you quickly build autocomplete experiences ?? Autocomplete v1 is in an alpha phase and early feedback is w

Algolia 2.3k Jan 6, 2023
🔮 Fast and full-featured autocomplete library

A JavaScript library that lets you quickly build autocomplete experiences All you need to get started is: A container to inject the experience into Da

Algolia 2.3k Jan 1, 2023
Autocomplete - Simple accessible autocomplete for vanilla javacript with support for remote & local data, ~3KB gzip

Autocomplete - Simple accessible autocomplete for vanilla javacript with support for remote & local data, ~3KB gzip

Grzegorz Tomicki 58 Dec 24, 2022
A lightweight, fully-featured, modular, typescript-compatible javascript library for Paymongo.

paymongo.js A lightweight, fully-featured, modular, typescript-compatible javascript library for PayMongo. Installation npm install paymongo.js # or y

Prince Carlo Juguilon 15 Nov 23, 2022
A fully-featured Node.js REST client built for ease-of-use and resilience

flashheart A fully-featured Node.js REST client built for ease-of-use and resilience flashheart is built on http-transport to provide everything you n

BBC 118 Jun 21, 2022
Fully featured clean-css plugin for Visual Studio Code

vscode-clean-css Fully featured clean-css plugin for Visual Studio Code. Install Execute Extensions: Install Extensions command from Command Palette (

Shogo Sensui 2 Nov 9, 2021
This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configured and ready to use in real world projects!

Nuxt 3 Starter This repo contains a fully configured nuxt 3 instance supporting TypeScript and several considered as useful libraries, fully configure

Ali Soueidan 26 Dec 27, 2022
Simple autocomplete pure vanilla Javascript library.

autoComplete.js ✨ Simple autocomplete pure vanilla Javascript library. ?? Live Demo v8.3 autoComplete.js is a simple pure vanilla Javascript library t

Tarek 3.7k Dec 31, 2022
:bird: :zap: Bluebird is a full featured promise library with unmatched performance.

Got a question? Join us on stackoverflow, the mailing list or chat on IRC Introduction Bluebird is a fully featured promise library with focus on inno

Petka Antonov 20.2k Jan 5, 2023
:bird: :zap: Bluebird is a full featured promise library with unmatched performance.

Got a question? Join us on stackoverflow, the mailing list or chat on IRC Introduction Bluebird is a fully featured promise library with focus on inno

Petka Antonov 20.2k Dec 31, 2022
A full-featured Solana Metaplex Candymachine client-side library in Typescript

Candymachine Client SDK A full-featured Solana Metaplex Candymachine client-side library in Typescript Disclaimer: The SDK is currently a pre-alpha ve

Boxfish Studio 36 Nov 10, 2022