πŸ“ A multiselect component in Pure JS - Compatible with IE11

Overview

Iconic Multiselect

License: MIT Version

A multiselect component written in pure JavaScript - Also compatible with IE11

Default template:

Custom template:

πŸš€ Try live demo

Getting Started

1. Link the required files

Firstly, the script and the CSS stylesheet need to be included in your HTML file. The multi-select.css file can be modified to change the default theme of the component.

<head>
  <link rel="stylesheet" href="multi-select.css" type="text/css" />
</head>

<script src="multi-select.js" type="text/javascript"></script>

2. Create a select tag

Secondly, within your HTML file, create a <select> tag which you want to turn into a multiselect. Do not forget to set an id on your <select> tag. If the attribute selected is set in one (or more) of your options, the option(s) will be automatically added to the selected options at initialization.

<select id="foods">
  <option value="bread">Bread</option>
  <option selected value="cereal">Cereal</option>
  <option selected value="pasta">Pasta</option>
  <option value="rice">Rice</option>
  <option value="meat">Meat</option>
  <option value="fish">Fish</option>
</select>

3. Initialize the Iconic Multiselect component

Finally, target the id of your <select> tag in the options and initialize the component with the .init() method. You may also specify further options. (see configuration)

<script type="text/javascript">
  const multiSelect = new IconicMultiSelect({
    select: "#foods",
  });

  multiSelect.init();
</script>

Configuration

1. Overview

Option Default Type
data [] Object[]
itemTemplate null string
noData No data found. string
noResults No results found. string
placeholder Select... string
select* none string
textField null string
tagTemplate null string
valueField null string

* This option is compulsory

data*

The component can be configured with data set in the configuration fields. It must be an Array of Objects. If a property named selected is set to true in one of your object, the option will be automatically added to the selected options at initialization.

itemTemplate

This option allows to define a custom template for the items rendered in the popup list. Custom item template can contains placeholders. These are indicated with a dollar sign and curly braces (${your_item_property_name}).

noData

Text to display if there is no data found in the <select> tag or in the data field.

noResults

Text to display if there is no results when the option list is filtered.

placeholder

Text to display in the input placeholder.

select

The <select> tag from which the component is initialized.

tagTemplate

This option allows to define a custom template for the tags rendered in the input list. Custom tag template can contains placeholders. These are indicated with a dollar sign and curly braces (${your_item_property_name}).

textField

The field of the data object that provides the text content.

valueField

The field of the data object that provides the value.

* IMPORTANT: When data is provided, valueField and textField should also be set.

2. Example

// Default template
<script type="text/javascript">
  const multiSelect = new IconicMultiSelect({
    customCss: true,
    data: [
      { valueName: "bread", itemName: "Bread" },
      { valueName: "rice", itemName: "Rice" },
      { valueName: "pasta", itemName: "Pasta" },
    ],
    noData: "No food item found.",
    noResults: "No results found in this list.",
    placeholder: "Select a food item...",
    select: "#foods",
    textField: "itemName",
    valueField: "valueName",
  });
</script>

// Custom template
<script type="text/javascript">
  const multiSelect = new IconicMultiSelect({
    select: "#employees",
    data: [
      { text: "John Doe", value: "john_doe", imageUrl: "face1.png", location: "New York, USA" },
      { text: "Clara Smith", value: "clara_smith", imageUrl: "face2.jpg", location: "Paris, France" },
      { text: "Morgane Amroc", value: "morgane_amroc", imageUrl: "face3.png", location: "Milan, Italy" },
      { text: "Peter Goldenfield", value: "peter_goldenfield", imageUrl: "face4.jpg", location: "Los Angeles, USA" },
    ],
    valueField: "value",
    textField: "text",
    tagTemplate:
      '<div class="demo-tag-template"><span class="demo-tag-template__img" style="background-image: url(./${imageUrl});"></span> ${text}</div>',
    itemTemplate:
      '<div class="demo-template"><span class="demo-template__img" style="background-image: url(./${imageUrl});"></span> ${text} - ${location}</div>',
    placeholder: "Select an employee...",
  });
</script>

Methods

.init()

Initialize the component with all its settings.

.subscribe()

Listen for all events.

Example:

JavaScript: 

multiSelect.subscribe(function (event) {
  console.log(event);
});
Console:

Object : { action: "ADD_OPTION", value: "pasta", selection: (1) [...] }

Contributing

Iconic Multiselect is an open-source project. Contributions of any kind are welcome and appreciated. Feel free to open an issue or request a feature. Pull requests are also welcome.

Author

License

This project is open source and available under the MIT License.

Comments
  • multiple instances on one page is not working

    multiple instances on one page is not working

    When you create 2 instances on one page than is this plugin confused and it works not correct.

    the second instance has any entries and the first one all entries

    opened by ChristianSchmidt1981 1
  • v0.4.0

    v0.4.0

    Changed :

    • Borders are set with box-shadow instead of border property
    • Changed Multiselect height

    Fixed :

    • arrow-selected border property not showing in IE11
    • Event click on items not fired on initialization of the component in IE11
    opened by sidneywm 0
  • Merge Dev into Master v0.3.0

    Merge Dev into Master v0.3.0

    Changes :

    Readme.md has been updated
    Comments have been also updated
    

    Add :

    It is now possible to select items with ArrowUp and ArrowDown keys
    You can confirm your choice with the Enter key
    New polyfills have been added to support these new features
    It is now possible to add data items in the configuration
    
    opened by sidneywm 0
  • Merge pull request #1 from sidneywm/dev

    Merge pull request #1 from sidneywm/dev

    Changes :

    • Readme.md has been updated
    • Comments have been also updated

    Add :

    • It is now possible to select items with ArrowUp and ArrowDown keys
    • You can confirm your choice with the Enter key
    • New polyfills have been added to support these new features
    • It is now possible to add data items in the configuration
    opened by sidneywm 0
  • size of multiselect

    size of multiselect

    Hello, I'm trying to change the size (height and width) of the iconic multiselect, or to change the maximum number of items to show when the list is open (like maxlength), but I didn't succeed. Is it possible ? thanks a lot

    opened by neeqkowlah 2
  • Setting on multiple select elements via classname does not work

    Setting on multiple select elements via classname does not work

    Hi! If you have multiple select elements on a page (e.g. a table with rows and each row has a select form element) you can't set the multiselect plugin on all elements using the class property.

    For instance:

        <select class="foobar">
            <option value="bread">Bread</option>
            <option value="cereal">Cereal</option>
            <option value="pasta">Pasta</option>
            <option value="rice">Rice</option>
            <option value="meat">Meat</option>
            <option value="fish">Fish</option>
        </select>
    
        <select class="foobar">
            <option value="bread">Bread</option>
            <option value="cereal">Cereal</option>
            <option value="pasta">Pasta</option>
            <option value="rice">Rice</option>
            <option value="meat">Meat</option>
            <option value="fish">Fish</option>
        </select>
    

    This bit will only initialize the multiselect on the first select element, not the second:

    const foobar = new IconicMultiSelect({
        select: ".foobar",
    });
    
    foobar.init();
    

    As a work around, you can do this:

      document.querySelectorAll("select").forEach(function (el) {
          const foobar = new IconicMultiSelect({
              select: "#" + el.id,
          });
    
          foobar.init();
      })
    

    But this is convoluted, and it requires that every select element has an id property.

    opened by netsensei 1
  • multibox plugin is not selecting the option-tags

    multibox plugin is not selecting the option-tags

    I've a selectbox with option-tags. Than I am selecting one entry with this plugin, but the correct option-tag don't get the property "selected". This is not connected.

    I added this feature on this way

    ` multiSelect.subscribe(function(event) { switch (event.action) { case 'ADD_OPTION': $(selectorString + " option[value='" + event.value + "']").prop('selected', 'selected'); break;

                case 'REMOVE_OPTION':
                    $(selectorString + " option[value='" + event.value + "']").prop('selected', '');
                    break;
            }
        });`
    
    opened by ChristianSchmidt1981 5
  • multibox is not showing selected entries initial

    multibox is not showing selected entries initial

    I've a select box with some selected entries in the html-code.

    than i am init the multi-box with

    ` const multiSelect = new IconicMultiSelect({ select: selectorString, customCss: true });

        multiSelect.init();`
    

    but the initial selected option-tags in the selectbox are not visible.

    I could add it with

    $(selectorString + " option[selected='selected']").each(function() { const value = this.value; const target = Array.from(multiSelect.domElements.options).find(function (el) { return el.dataset.value === value; }); multiSelect._handleOption( target, false); })

    for making initial entries are visible.

    opened by ChristianSchmidt1981 2
Releases(v0.7.0)
Autocomplete component created with pure javascript

Pickle Complete Pickle complate is a autocomplate component written as completely pure javascript. Just send json object or request information have f

Kadir Barış Bozat 2 Jul 5, 2022
DateTimePickerComponent is a very lightweight and dependency-free web component written in pure JavaScript

DateTimePickerComponent Description DateTimePickerComponent is a very lightweight (just over 20KB) and dependency-free web component written in pure J

null 14 Dec 24, 2022
This simple project, show how work with async Fetch, function component and class component

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

DaliyaAsel 2 Feb 17, 2022
dynamic-component-app is an angular application for dynamic component template creation

MyApp This project was generated with Angular CLI version 14.1.0. Development server Run ng serve for a dev server. Navigate to http://localhost:4200/

Aniket Muruskar 7 Aug 26, 2022
A lightweight, fully-featured, modular, typescript-compatible javascript library for Paymongo.

paymongo.js A lightweight, fully-featured, modular, typescript-compatible javascript library for PayMongo. Installation npm install paymongo.js # or y

Prince Carlo Juguilon 15 Nov 23, 2022
zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

Marto.eth 10 Aug 25, 2022
esbuild plugin to generate mix-manifest.json file compatible with Laravel Mix.

esbuild-mix-manifest-plugin An esbuild plugin to generate a mix-manifest.json compatible with Laravel Mix. Installation You can install the plugin via

Stefan Zweifel 6 Dec 25, 2022
Exports a JPDB deck to a Yomichan compatible frequency list.

JPDB Frequency List A frequency list generated using most of the jpdb corpus can be found in the releases. It is not exhaustive, as there is no deck a

marv 17 Nov 16, 2022
Making webshell and terminal supports trzsz ( trz / tsz ), which similar to rz / sz, and compatible with tmux.

trzsz.js Making webshell and terminal supports trzsz ( trz / tsz ), which similar to ( rz / sz ), and compatible with tmux. Why? Considering laptop ->

null 95 Jan 3, 2023
Spiner bot to buy and sell tokens on ETH and ERC compatible chains as soon as liquidity is added and trade is enabled.

An open-source defi sniper. open-sniper is free to download. Premium Services Now Available While open-sniper is free and open-source, if you want the

spacemonk 4 Apr 21, 2022
A Multichain crypto wallet library that supports Ethereum, Solana and other EVM compatible blockchains.

Multichain Crypto Wallet A Multichain crypto wallet library that supports Ethereum, Solana and other EVM compatible blockchains. Installation npm inst

Abdulfatai Suleiman 117 Jan 2, 2023
Multi-chain sniper bot to buy and sell tokens on ETH compatible chains. Features include instant or mempool sniping, rug protection, and sell management.

An open-source defi sniper. defi-sniper is free to download. NEW Community telegram group: https://t.me/+aBLUmP1UnypiNTVh Premium Services Now Availab

spacemonk 6 May 3, 2022
Rebase.co for German GmbH's. Flip your German GmbH to Delaware to be venture-compatible

???? ???? FlipGmbH Rebase.co for German GmbH's. Flip your German GmbH to a Delaware C-Corp to be compatible for international venture funding. Inspire

Peer Richelsen 16 Aug 19, 2022
Color palette text parser to a function, compatible with GMT, GDAL, GRASS, PostGIS, ArcGIS

cpt2js Color palette text parser to a function, input compatible with GMT, GDAL, GRASS, PostGIS, ArcGIS Demo From GDAL docs: The text-based color conf

WeatherLayers 5 Dec 4, 2022
Hashlips NFT Mint Dapp modified by fazelpejmanfar (Compatible with ERC721A)

Welcome to HashLips ?? All the code in these repos was created and explained by HashLips on the main YouTube channel. Edited By Fazel Pejmanfar and co

Fazel Pejamanfar 27 Nov 30, 2022
Generate type definitions compatible with @kintone/rest-api-client

kintone-form-model-generator Generate type definitions compatible with @kintone/rest-api-client Prerequirements Node.js (>=12) Install # Install npm i

Yuuki Takahashi 5 Dec 15, 2022
Browser library compatible with Node.js request package

Browser Request: The easiest HTTP library you'll ever see Browser Request is a port of Mikeal Rogers's ubiquitous and excellent [request][req] package

Iris Couch 357 Nov 11, 2022
chain-syncer is a module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realtime. Reliable.

Chain Syncer Chain Syncer is a JS module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realti

Miroslaw Shpak 10 Dec 15, 2022
An Ethereum-compatible blockchain with a giant capacity for storage

goliath The Goliath blockchain is an Ethereum L2 with a giant capacity. For devs, it means you'll never need another chain. No bridges, no new languag

Liam Zebedee 17 Dec 23, 2022