npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typeahead-multiselect

v1.1.1

Published

Tiny extension to twitter typeahead to allow multiple selections

Downloads

7

Readme

Typeahead-multiselect: a tiny extension to twitter typeahead to allow multiple selections

Typeahead-multiselect extends the current functionality of Twitter Typeahead to allow multiple selections.

Dependencies

Typeahead-multiselect depends on both jQuery and Typeahead.js. Be sure to include them as follows:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
<script src="typeahead-multiselect.min.js"></script>

To use bootstrap styles, include typeaheadjs.css.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" media="screen">
<link rel="stylesheet" href="typeaheadjs.css" type="text/css" media="screen">

or use the default styling:

<link rel="stylesheet" href="typeahead-multiselect.min.css" type="text/css" media="screen">

Usage

You can use Typeahead-multiselect using the same signature as Typeahead. See it live

<div id="typeaheadmulti">
  <input class="typeahead" type="text" placeholder="Search Languages">
</div>
var language = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.whitespace,
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  local: ["English", "Arabic", "Japanese"]
});

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

Options

All typeahead.js options are valid. In addition:

selectionsContainer: A Jquery-valid selector for the container where the selections will be added.

Dataset templates:

Templates should either be a string of a function that returns a string to be rendered. Handlebar temaplates are not supported.

emptySelection: Will be used to fill the container when no selections are selected. selection: Should be a function that takes the selected object and returns a html string.

Events

selectionAdded and selectionRemoved are fired after a selection is added or removed from the selection container.

Styling

You can use the styles accompanied with the package typeahead-multiselect.css.min, which provides styling for the suggestion container. Selection container and selections are classed as list-group and list-group-item for bootrap compatiblity. If you want to use Boostrap for styling, make sure to include typeaheadjs.css.

Limitations

These are the current limitations for typeaheadmulti. All these limitations can be easily supported (the souce code is marked with TODOs). Contributions through pull requests all very welcome.

  • No support for multiple datasets.
  • Setting the selections programmatically by $.typehead('val', someVal)

License

Licensed under the MIT License.