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

multi.js

v0.5.3

Published

A user-friendly replacement for select boxes with multiple attribute enabled

Downloads

2,726

Readme

multi.js

multi.js is a user-friendly replacement for select boxes with the multiple attribute. It has no dependencies, is mobile-friendly, and provides search functionality. multi.js is also easy to style with CSS and optionally supports jQuery.

Check out the demo.

Preview of multi.js

Installation

Install with npm:

npm install --save multi.js

Install with yarn:

yarn add multi.js

After installing with npm or yarn, import both the library and stylesheet:

import multi from "multi.js/dist/multi-es6.min.js";
import "multi.js/dist/multi.min.css";

Install manually by cloning or downloading the repository to your project and including both files in the dist directory.

<link rel="stylesheet" type="text/css" href="multijs/dist/multi.min.css">
<script src="multijs/dist/multi.min.js"></script>

Usage

multi.js can be applied to any select element with the multiple attribute enabled.

var select_element = document.getElementById("your_select_element");
multi(select_element);

To customize multi a few options can be passed with the function call. Below are all the default values.

multi(select_element, {
    "enable_search": true,
    "search_placeholder": "Search...",
    "non_selected_header": null,
    "selected_header": null,
    "limit": -1,
    "limit_reached": function () {},
    "hide_empty_groups": false,
});

Column headers

To add headers to both columns set values for these options:

multi(select_element, {
    'non_selected_header': 'All options',
    'selected_header': 'Selected options'
});

Limit

You can add a limit of option selected for your select using the limit parameter. Default is -1, which means "no limit".

multi(select_element, {
    'limit': 10
});

Additionally, there a callback is available: limit_reached, invoked when the user selects the last available option before reaching the limit (for example, the 10th element of a maximum of 10).

multi(select_element, {
    'limit': 10,
    'limit_reached': function () {
      alert('You have selected 10/10 elements.');
    }
});

jQuery

multi.js is fully native Javascript but also has jQuery support. If you have jQuery included multi can be applied to a select element as follows:

$('#your_select_element').multi();

TODO

  • ~~Native Javascript, no jQuery~~
  • ~~Support for disabled options~~
  • ~~Support for optgroups~~
  • Browser testing
  • Support for retrieving options by AJAX
  • Tests

Contributing

All contributions, big and small, are very welcome.

Use Prettier to format all code after editing. Build the project with Grunt and bump the version number before creating a pull request.

License

multi.js is licensed under MIT.