Converts select multiple elements into dropdown menus with checkboxes

Overview

jquery-multi-select

Converts element is hidden, but still present in the document, and will be updated with any selections made via the custom dropdown menu.

Any labels associated with the original ">



You’ll want to run this:

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

You can pass a number of options into .multiSelect() to customise the HTML output it generates. Eg:

', menuHTML: '

Options related to markup:

Option Default value Notes
containerHTML '
'
menuHTML '
'
buttonHTML ''
menuItemsHTML '
'
menuItemHTML '
presetsHTML '
'
modalHTML undefined Set this to some HTML (eg:
) to enable the modal overlay.
activeClass 'multi-select-container--open' The class that will be added to the container element when the menu is "open".

Options related to labels and (select) options:

Option Default value Notes
noneText '-- Select --' Shown in the button when no options have been selected.
allText undefined Shown in the button when all options have been selected.
presets undefined An array of preset option groups, see the demo for an example.

Options related to positioning:

Option Default value Notes
positionMenuWithin undefined 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.
positionedMenuClass 'multi-select-container--positioned' The class that will be added to the container, when the menu is about to extend beyond the right edge of the positionMenuWithin element.
viewportBottomGutter 20 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.
menuMinHeight 200 The minimum height, in pixels, that the menu will be reduced to before the viewportBottomGutter option is ignored and the menu is allowed to extend beyond the bottom edge of the viewport.

See a demo

Run make demo, or open demo/index.html in your web browser.

Run the tests

Run make test, or open test/SpecRunner.html in your web browser.

Compile minimized version

You'll need the Closure Compiler, which you can get with brew install closure-compiler or directly from Google's website. If you use brew (or otherwise create a closure-compiler script in your PATH), you can run make dist, or otherwise you can run: make dist COMPILER='java -jar path-to-compiler.jar'.

Comments
  • Config option to stop menu extending outside a parent element

    Config option to stop menu extending outside a parent element

    If positionMenuWithin is specified, the width of the menu is artificially constrained, such that it does not extend outside the bounds of the positionMenuWithin element when it is shown.

    This was the first test that really required CSS styles (for the width and position calculations) so it necessitated a tidying up of the CSS files in /demo.

    opened by zarino 2
  • Dynamically change selected values

    Dynamically change selected values

    Thanks for the library, it works really well for us. I couldn't find how to dynamically change the values, but I am sure there must be a way. Could you provide an example?

    opened by molinch 1
  • Doesn't work with POST, only GET

    Doesn't work with POST, only GET

    I found that submitting the form with GET gives all the selections in the query string as expected. However, when substituting POST for the submission method there is only one of the multiple selections, the final one, in the POST array received by the server. To demonstrate this see the attached file ( change index.txt to index.php) Is this a bug or is this plugin designed to work only with GET submission?

    index.txt

    opened by TriangleDigital 1
  • Option to enable a modal background element

    Option to enable a modal background element

    If HTML markup is provided via the modalHTML option, the resulting element will be inserted before the menu, and clicks on the element will close the menu.

    demo/index.html includes an example of how this can be used.

    image

    opened by zarino 1
  • Allow people to select pre-set groups of options

    Allow people to select pre-set groups of options

    Eg the "All categories" radio button here:

    dropdown

    But, not necessarily limited to just the "empty" case. "empty" is just one example of a pre-set collection of options (and empty collection!) – you might equally have a collection of "my favourite options", or whatever, that should tick and untick the correct options in the menu below it.

    opened by zarino 1
  • Remove `for` attribute from labels when creating a multiSelect

    Remove `for` attribute from labels when creating a multiSelect

    It was noted that it’s bad practice to leave a <label> pointing at a hidden form element. So, if the <select> we’re converting is referenced in the for attribute of any <label>s in the document, we remove those for attribute, so the label isn’t left pointing at a hidden form element.

    Fixes #28.

    opened by zarino 0
  • .multiSelect() should replace any <label>s with an non-<label> element, for better accessibility

    .multiSelect() should replace any

    It was suggested by a recent FixMyStreet accessibility audit, that having a <label> continue to point to the (hidden) native <select> element isn’t ideal.

    Perhaps .multiSelect() should replace the labels with a different element (<span>? <div>?) or maybe just remove the for attribute from any labels, so that assistive devices don’t get conflicting messages on what the label element is for?

    Noted in https://github.com/mysociety/societyworks/issues/2785.

    opened by zarino 0
  • Add parameter to create a preset that selects all.

    Add parameter to create a preset that selects all.

    In lieu of larger changes suggested by #13/#14, this adds an all parameter to the preset item that acts the same as if you had listed all the options manually. This lets you create an All preset without listing the options as in my example in #13, but doesn't add any other functionality.

    opened by dracos 0
  • Prevent long dropdowns from extending beyond viewport

    Prevent long dropdowns from extending beyond viewport

    Fixes #10.

    Apols for lack of integration test – I couldn’t work out how to append the $select to the DOM, inside the Jasmine test, so that the heights of the menu and the viewport could be measured. I seem to recall us having a hard time doing this before too, when we tried to write tests for #5 (and ultimately gave up).

    opened by zarino 0
  • Automatically set a sensible max-height for dropdown

    Automatically set a sensible max-height for dropdown

    In multi-selects with dozens, or even hundreds, of menu items, the .multi-select-menu can become unusably long, extending thousands of pixels down the page.

    Ideally, $.multiSelect would work out the optimum max-height for the menu, such that it stops just above the bottom edge of the viewport, and with overflow: scroll set, the menu will be scrollable.

    We’ll probably want to place a sensible minumum bound on this, so that, if a multi-select is triggered near the bottom of the window, we still get a usable .multi-select-menu that extends below the egde of the viewport, rather than an unusable one that stops inside the viewport.

    opened by zarino 0
  • Specify all external settings in quotes.

    Specify all external settings in quotes.

    This means the Closure Compiler does not try and rename them in advanced mode, which would break everything. All tests pass when Closure Compiled, as long as you specify the jQuery contrib extern. If things are gzipped, saves another 10% over simple gzipped.

    File sizes:

    • Before this PR, full size: 9285
    • Uncompressed, ungzipped: 9375
    • Simple CC, ungzipped: 5365 (57% of full size)
    • Advanced CC, ungzipped: 4241 (45%)
    • Uncompressed, gzipped: 2423 (26%)
    • Simple CC, gzipped: 1702 (18%) (70% of uncompressed gzipped)
    • Advanced CC, gzipped: 1517 (16%) (63% of uncompressed gzipped)
    opened by dracos 0
  • Append allText to selected Text in button

    Append allText to selected Text in button

    When defined a allText option, then select the options, it would be nice to add the allText before.

    Proposal to change the updateButtonContents function.

    Change this:

    if (selected.length == 0) {
      this.$button.text( this.settings['noneText'] );
    } else if ( (selected.length === options.length) && this.settings['allText']) {
      this.$button.text( this.settings['allText'] );
    } else {
      this.$button.text( selected.join(', ') );
    }
    

    To this:

    if (selected.length == 0) {
      this.$button.text( this.settings['noneText'] );
    } else if ( (selected.length === options.length) && this.settings['allText']) {
      this.$button.text( this.settings['allText'] );
    } else if (this.settings['noneText']){
      this.$button.text( this.settings['noneText'] + ': ' + selected.join(', ') );
    } else {
      this.$button.text( selected.join(', ') );
    }
    
    opened by patrick-abc 3
  • Populating select combobox options dynamically with AngularJS 1.x.xx

    Populating select combobox options dynamically with AngularJS 1.x.xx

    This control works well with static options defined in HTML.

    Is there a way to use this control to populate options from AngularJS using select / ng-options definitions ? If affirmative, are there any examples available ?

    opened by fyoshino 2
  • When re-opening a menu in menuShow the scrollbars are gone.

    When re-opening a menu in menuShow the scrollbars are gone.

    The first time the menu is opened, the script checks the menu size. If it would overflow, the max size is caculated and overflow is hidden. The second time, since overflow and size have not been reset, the same test return false and the size and overflow are now reset. And the menu overflows. Fix: if the size and overflow are reset before the test, everything's fine.

    opened by kenamat 0
  • Calling multiSelect() more than once

    Calling multiSelect() more than once

    Hi, thank you for the excellent code. Is there a way for us to call the multiSelect() more than once? I would like to call it more than once because I want to modify the checkbox selections dynamically after .mutltiSelect() was called the first time

    opened by kokleong9406 0
  • Unable to set the value to the control

    Unable to set the value to the control

    I am setting the options as follows where I am not setting the value field is not getting set, can some one help me

    function bindDropDown1(data) { $.each(data, function (i, x) { $('#selec1').append(<option value="${x.Id}">${x.Name}</option>); }); }

    Also if I would like to select few by default how can I do that

    opened by Github743 1
Owner
mySociety
We help people be active citizens
mySociety
Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support

JS Select Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support How to use To use the select plugins, two main file mu

Luigi Verolla 4 Mar 17, 2022
A JavaScript library for creating "select-all" checkboxes

SelectAllCheckbox v1.0 See LICENSE for this software's licensing terms. SelectAllCheckbox is a JavaScript library which makes it easy to create "selec

Kurtis LoVerde 1 Jul 27, 2021
A good looking help command made with discord.js with select menus. Works with prefix and slash commands too!

fancy-help-command A good looking help command made with discord.js with select menus. Works with prefix and slash commands too! Dependencies: Select

LunarCodes 11 Dec 12, 2022
Create a deep copy of a set of matched elements with the dynamic state of all form elements copied to the cloned elements.

jq-deepest-copy FUNCTION: Create a deep copy of a set of matched elements while preserving the dynamic state of any matched form elements. Example Use

Michael Coughlin 5 Oct 28, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support.

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022
Select creates a dropdown list of items with the selected item in closed view.

Native Base Select ?? This module includes a customizable multi-select and a single select component for Native Base. The package is both Android and

Blump Tech 3 Dec 25, 2022
A custom select dropdown. This is something that is not too difficult to make.

Custom-Dropdown-JS A custom select dropdown using basic JS fucntionality. This is something that is not too difficult to make. But it shows that you h

Devanshu Vashishtha 2 Mar 26, 2022
a jquery searchable select dropdown

Select Search A simple jquery search on select options plugin for your website How To Use Just create an html structure that contains select tag e.g.

Juliver Galleto 1 Sep 25, 2020
Dropdown select box for bootstrap 5

dselect Dropdown select box for bootstrap 5 Demo Features Placeholder Multiple Search Creatable Clearable Sizing Validation Installation Install dsele

null 30 Dec 21, 2022
Multiple level dropdown works with Bootstrap 5, just like native support.

Bootstrap 5 Multiple Level Dropdown. For Bootstrap 4, please visit Bootstrap 4 Multiple Level Dropdown Using official HTML without adding extra CSS st

Dallas Lu 17 Dec 13, 2022
A typescript transform that converts exported const enums into object literal.

ts-transformer-optimize-const-enum A typescript transformer that convert exported const enum into object literal. This is just like the one from @babe

Fonger 22 Jul 27, 2022
Converts an iterable, iterable of Promises, or async iterable into a Promise of an Array.

iterate-all A utility function that converts any of these: Iterable<T> Iterable<Promise<T>> AsyncIterable<T> AsyncIterable<Promise<T>> Into this: Prom

Lily Scott 8 Jun 7, 2022
A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

Welcome to the Generative GIF Engine v2.0.4 ?? [8 minute read] This python and node app generates layered-based gifs to create NFT gif art! It is fast

Jalagar 112 Jan 2, 2023
A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

Welcome to the Generative Animated Engine v3.0.1 ?? [8 minute read] This repo used to be called jalagar/Generative_Gif_Engine but because it now suppo

Jalagar 47 May 24, 2022
Fancytree - JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Fancytree Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkb

Martin Wendt 2.6k Jan 9, 2023
iOS 7 style switches for your checkboxes

Description Switchery is a simple component that helps you turn your default HTML checkbox inputs into beautiful iOS 7 style switches in just few simp

Alexander Petkov 2.1k Dec 31, 2022
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.4k Dec 25, 2022
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.5k Aug 24, 2022