Apr 25

Version 1.1 Released!

  • Updated the license to jQuery standard GPL/MIT dual license
  • Moved the plugin to github by popular demand
  • Escape and tab keys now work (Thanks Dirk Bergstrom)
  • Can use settings.minChars to specify how many characters need to be type before a search is started (Thanks Dirk Bergstrom)
  • Can now prepopulate the list by settings settings.prePopulate with an array of {id: n, name: blah} (Thanks Nathan Edminster)
  • Can now change the name of the query param using settings.queryParam (Thanks Elijah Insua)
  • Can now preprocess the returned search results by specifying a settings.onResult function (Thanks Elijah Insua)
  • Can now set the content-type of returned data using settings.contentType (Thanks Elijah Insua)
  • Can now specify the maximum number of tokens allowed using settings.tokenLimit (Thanks Chris Dary and Paul)
  • Can now grab results from anywhere in the json using settings.jsonContainer (Thanks Richard G)
  • Can now fetch results using POST as well as GET with settings.method = “POST” (Thanks ellisgl)

Overview

This is a jQuery plugin to allow users to select multiple items from a predefined list, using autocompletion as they type to find each item. You may have seen a similar type of text entry when filling in the recipients field sending messages on facebook.

Features

  • Intuitive UI for selecting multiple items from a large list
  • Layout controlled fully in CSS, easily customisable
  • Result caching reduces server load
  • No images required, just the plugin’s .js file and some CSS
  • Handles json search data for autocompletion
  • Smooth animations when results load
  • Select items using the mouse or keyboard

Screenshots

Vertical list style item selection
Vertical list style item selection

Facebook style item selection
Facebook style item selection

Demo

A live demo of the token input is available here.

Usage

  • Make sure you have jquery script included on your page
  • Include jquery.tokeninput.js on your page
  • Include one of the provided stylesheets, or make your own
  • Create a server-side script (php/rails/django anything goes) to generate the search results.
    The script itself can fetch data from wherever you like, for example a database or a hardcoded list, but it must do the following:

    • Take exactly one GET parameter named “q” which will contain the query string. E.g. http://www.example.com/myscript?q=query
    • Output JSON search results in the following format:
      [{"id":"856","name":"House"},
       {"id":"1035","name":"Desperate Housewives"},
       {"id":"1048","name":"Dollhouse"},
       {"id":"1113","name":"Full House"}
      ]
  • Turn text inputs into tokeninputs using jQuery and point them to your results script:
    <script type="text/javascript">
    $(document).ready(function () {
      $("#my-text-input").tokenInput("/url/to/your/script/");
    });
    </script>
  • A list of selected item ids is created inside the original text entry, process them as usual when the form is submitted.

License

This plugin is released under a dual license. You can choose either the GPL or MIT license depending on the project you are using it in and how you wish to use it.

Download

Quick Download

Please don’t use these links directly in your scripts, I might change their location at any time. Instead, download them and use your own local copy.

Github Project

If you would like to contribute to this plugin, check out the github repository here:
http://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin/tree/master