Press "Enter" to skip to content

JavaScript Autocomplete With Multiple Selection | SelectPure Component

SelectPure is a pure JavaScript library for creating single or multiple elegant controls with support for auto-completion and dynamic data rendering.

multi select autocomplete, autocomplete multiple select javascript, multi select autocomplete jquery example with code, autocomplete multiselect dropdown jquery

How to make use of it:

Install the SelectPure.

# Yarn
$ yarn add select-pure

# NPM
$ npm install select-pure --save

Import the SelectPure library.

import SelectPure from "select-pure";

Or instantly include the bundled JavaScript on the webpage.

<script src="bundle.min.js"></script>

Create a container wherein you wish to render the choice control.

<span class="example"></span>

Define an array of options for the choice.

const myOptions = [
  {
    label: "New York",
    value: "NY",
  },
  {
    label: "Washington",
    value: "WA",
  },
  {
    label: "California",
    value: "CA",
  },
  {
    label: "New Jersey",
    value: "NJ",
  },
  {
    label: "North Carolina",
    value: "NC",
  },
],

Create a brand new choose control inside the container component you simply created.

var instance = new SelectPure(".example", {
    options: myOptions
});

Enable the Multi-Select functionality.

var instance = new SelectPure(".example", {
    options: myOptions,
    multiple: true // default: false
});

Enable the Autocomplete functionality.

var instance = new SelectPure(".example", {
    options: myOptions,
    autocomplete: true // default: false
});

Set the pre-selected value(s).

var instance = new SelectPure(".example", {
    options: myOptions,
    value: ["NY", "CA"]
});

Customize the icon displayed within the chosen options.

var instance = new SelectPure(".example", {
    options: myOptions,
    icon: "fa fa-times" // uses Font Awesome
    inlineIcon: false // custom cross icon for multiple select.
});

Execute a callback perform on change.

var instance = new SelectPure(".example", {
    options: myOptions,
    onChange: value => { console.log(value); }
});

Customize the placeholder when no value is chosen.

var instance = new SelectPure(".example", {
    placeholder: false
});

Get the at present chosen value.

instance.value();

Reset the select.

instance.reset();

Default CSS classes.

var instance = new SelectPure(".example", {
    options: myOptions,
    classNames: {
      select: "select-pure__select",
      dropdownShown: "select-pure__select--opened",
      multiselect: "select-pure__select--multiple",
      label: "select-pure__label",
      placeholder: "select-pure__placeholder",
      dropdown: "select-pure__options",
      option: "select-pure__option",
      autocompleteInput: "select-pure__autocomplete",
      selectedLabel: "select-pure__selected-label",
      selectedOption: "select-pure__option--selected",
      placeholderHidden: "select-pure__placeholder--hidden",
      optionHidden: "select-pure__option--hidden",
    }
});

The default CSS styles.

.select-wrapper {
  margin: auto;
  max-width: 600px;
  width: calc(100% - 40px);
}

.select-pure__select {
  align-items: center;
  background: #f9f9f8;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
  color: #363b3e;
  cursor: pointer;
  display: flex;
  font-size: 16px;
  font-weight: 500;
  justify-content: left;
  min-height: 44px;
  padding: 5px 10px;
  position: relative;
  transition: 0.2s;
  width: 100%;
}

.select-pure__options {
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
  color: #363b3e;
  display: none;
  left: 0;
  max-height: 221px;
  overflow-y: scroll;
  position: absolute;
  top: 50px;
  width: 100%;
  z-index: 5;
}

.select-pure__select--opened .select-pure__options {
  display: block;
}

.select-pure__option {
  background: #fff;
  border-bottom: 1px solid #e4e4e4;
  box-sizing: border-box;
  height: 44px;
  line-height: 25px;
  padding: 10px;
}

.select-pure__option--selected {
  color: #e4e4e4;
  cursor: initial;
  pointer-events: none;
}

.select-pure__option--hidden {
  display: none;
}

.select-pure__selected-label {
  background: #5e6264;
  border-radius: 4px;
  color: #fff;
  cursor: initial;
  display: inline-block;
  margin: 5px 10px 5px 0;
  padding: 3px 7px;
}

.select-pure__selected-label:last-of-type {
  margin-right: 0;
}

.select-pure__selected-label i {
  cursor: pointer;
  display: inline-block;
  margin-left: 7px;
}

.select-pure__selected-label i:hover {
  color: #e4e4e4;
}

.select-pure__autocomplete {
  background: #f9f9f8;
  border-bottom: 1px solid #e4e4e4;
  border-left: none;
  border-right: none;
  border-top: none;
  box-sizing: border-box;
  font-size: 16px;
  outline: none;
  padding: 10px;
  width: 100%;
}

Elegant Multi-Select Component With Autocomplete, SelectPure JavaScript component Plugin/Github, autocomplete multi select dropdown with checkbox jquery, select pure example, multiple select jquery

SelectPure-JavaScript-component


See Demo And Download

Official Website(dudyn5ky1): Click Here

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

Be First to Comment

    Leave a Reply

    Your email address will not be published.