Converts Select Multiple Items Into Dropdown Lists With Checkboxes

jquery-multi-select is to convert <select multiple> elements into dropdown lists with a checkbox for each <option> and this plugin that converts a regular multi-selection box into an easy-to-use dropdown menu with checkboxes to simplify selecting multiple options.

More advantages:

  • Supports optgroup and classes.
  • Custom patterns.
  • Allows you to select options from media.

How to make use of it:

1. Add the multi-select.js script to the webpage, after you’ve got loaded the most recent model of the jQuery library.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/src/jquery.multi-select.js"></script>

2. Let’s say you have a multi-select listing like this:

<select id="languages" name="languages" multiple>
  <option value="JavaScript">JavaScript</option>
  <option value="C++">C++</option>
  <option value="Python">Python</option>
  <option value="Ruby">Ruby</option>
  <option value="PHO">PHP</option>
  <option value="Pascal">Pascal</option>
</select>

3. Call the operate .multiSelect() on the chosen ingredient and we’re accomplished.

$('#languages').multiSelect();

4. Style the plugin within the CSS as follows:

.multi-select-container {
  display: inline-block;
  position: relative;
}

.multi-select-menu {
  position: absolute;
  left: 0;
  top: 0.8em;
  float: left;
  min-width: 100%;
  background: #fff;
  margin: 1em 0;
  padding: 0.4em 0;
  border: 1px solid #aaa;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  display: none;
}

.multi-select-menu input {
  margin-right: 0.3em;
  vertical-align: 0.1em;
}

.multi-select-button {
  display: inline-block;
  font-size: 0.875em;
  padding: 0.2em 0.6em;
  max-width: 20em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: -0.5em;
  background-color: #fff;
  border: 1px solid #aaa;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: default;
}

.multi-select-button:after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.4em 0.4em 0 0.4em;
  border-color: #999 transparent transparent transparent;
  margin-left: 0.4em;
  vertical-align: 0.1em;
}

.multi-select-container--open .multi-select-menu { display: block; }

.multi-select-container--open .multi-select-button:after {
  border-width: 0 0.4em 0.4em 0.4em;
  border-color: transparent transparent #999 transparent;
}

5. Possible plugin choices with default values.

$('#languages').multiSelect({

  // Custom templates
  'containerHTML': '<div class="multi-select-container">',
  'menuHTML': '<div class="multi-select-menu">',
  'buttonHTML': '<span class="multi-select-button">',
  'menuItemsHTML': '<div class="multi-select-menuitems">',
  'menuItemHTML': '<label class="multi-select-menuitem">',
  'presetsHTML': '<div class="multi-select-presets">',

  // sets some HTML (eg: <div class="multi-select-modal">) to enable the modal overlay.
  'modalHTML': undefined,

  // Active CSS class
  'activeClass': 'multi-select-container--open',

  // Text to show when no option is selected
  'noneText': '-- Select --',

  // Text to show when all options are selected
  'allText': undefined,

  // an array of preset option groups
  // presets: [{
  //   name: 'All categories',
  //   all: true // select all
  // },{
  //   name: 'My categories',
  //   options: ['a', 'c']
  // }]
  'presets': undefined,

  // CSS class added to the container, when the menu is about to extend beyond the right edge of the position Within element
  'positionedMenuClass': 'multi-select-container--positioned',

  // If you provide a jQuery object here, the plugin will add a class (see positionedMenuClass option) to the container when the right edge of the dropdown menu is about to extend outside the specified element, giving you the opportunity to use CSS to prevent the menu extending, for example, by allowing the option labels to wrap onto multiple lines.
  'positionMenuWithin': undefined,

  // The plugin will attempt to keep this distance, in pixels, clear between the bottom of the menu and the bottom of the viewport, by setting a fixed height style if the menu would otherwise approach this distance from the bottom edge of the viewport.
  'viewportBottomGutter': 20,

  // minimal height
  'menuMinHeight': 200
  
});

jQuery Plugin For Multiple Select With Checkboxes, jquery-multi-select Plugin/Github


See Demo And Download

Official Website(mysociety): Click Here

This superior jQuery/javascript plugin is developed by mysociety. For extra Advanced Usages, please go to the official website.

Related Posts

Cookie-Consent-Using-Bootstrap

How to Create a Simple Cookie Banner Consent Using Bootstrap 4

Cookie Consent Popup Javascript – Quick and simple tutorial for creating a simple Bootstrap cookie banner. If you have a website or blog with people visiting or…

Create-HTML-Terminals

Create Custom HTML Terminals With Pure JavaScript | shell.js

Custom HTML Terminals is A JavaScript library to create HTML terminals on web pages. The shell js JavaScript library offers a straightforward method to create Ubuntu, OS X,…

Bootstrap-Alert-Bootbox

Bootstrap Alert, Confirm, and Flexible Dialog Boxes | Bootbox

Bootbox.js is a small JavaScript library that allows you to create programming dialogs using Bootstrap templates, without having to worry about creating, managing, or removing any required…

Slider-fg-carousel

An Accessible Touch-enabled Slider Web Component | fg-carousel

fg-carousel Slider – A simple & modern slider web component to create versatile, accessible, touch-enabled picture carousels utilizing CSS scroll snap, Custom Element, and Intersection Observer API….

Tags-Input-Component

A Lightweight and Efficient Tags Input Component in Vanilla JS | tagify

tagify transforms an input field or textarea into a tags component, in an easy and customizable way, with great performance and a small code footprint, full of…

copy-to-clipboard-javascript

A Lightweight Library to Copy Text to Clipboard | CopyJS

CopyJS is a lightweight JavaScript library that allows you to copy plain text or HTML content to the clipboard. Must Read: Tiny Library for Copy Text In…