Multi-select Dropdown Component With Vanilla JavaScript – sellect.js

Category: Form | July 1, 2017
Author: lidia-freitas
Views Total: 3,494
Official Page: Go to website
Last Update: July 1, 2017
License: MIT

Preview:

Multi-select Dropdown Component With Vanilla JavaScript – sellect.js

Description:

sellect.js is a vanilla JavaScript plugin which converts a normal input into a multi-select dropdown UI where the users are able to select multiple items from an autocomplete/autosuggest list. Great for tag/token manager.

How to use it:

Include the needed Font Awesome for the icons.

<link rel="stylesheet" href="font-awesome.css">

Download and load the sellect.js’ JavaScript and Stylesheet in the document.

<link rel="stylesheet" href="sellect.css">
<script src="sellect.js"></script>

Create a normal input field:

<input type="text" id="my-element">

Create a new ‘sellect object and define the original and destination item lists in the JavaScript.

var mySellect = sellect("#my-element", {
    originList: ['banana', 'apple', 'pineapple', 'papaya', 'grape', 'orange', 'grapefruit', 'guava', 'watermelon', 'melon'],
    destinationList: ['banana', 'papaya', 'grape', 'orange', 'guava']
});

Initialize the plugin and done.

mySellect.init();

Callback functions available.

var mySellect = sellect("#my-element", {

    // Called when the destination list receives a new item
    onInsert: function( event, item ) {},

    // Called when an item is removed from destination list
    onRemove: function( event, item ) {}
    
});

API methods.

// Return a list of selected items
mySellect.getSelected();

// Return a list of unselected items
mySellect.getUnselected();

You Might Be Interested In:


Leave a Reply