Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanety/stimulus-multi-select


https://github.com/kanety/stimulus-multi-select

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# stimulus-multi-select

A stimulus controller for simple multiple select.

## Dependencies

* @hotwired/stimulus 3.0+

## Installation

Install from npm:

$ npm install @kanety/stimulus-multi-select --save

## Usage

Register controller:

```javascript
import { Application } from '@hotwired/stimulus';
import MultiSelectController from '@kanety/stimulus-multi-select';

const application = Application.start();
application.register('multi-select', MultiSelectController);
```

Import css:

```css
@import '@kanety/stimulus-multi-select';
```

Build html as follows:

```html




option1
option2
option3










```

### Options

#### max-options

Set max number of addable options:

```html



```

#### sort-options

Enable sorting when options moved:

```html



```

### Callbacks

```javascript
let element = document.querySelector('[data-controller="multi-select"]')
element.addEventListener('multi-select:added', (e) => {
console.log(e.detail.option); // added option
});
element.addEventListener('multi-select:removed', (e) => {
console.log(e.detail.option); // removed option
});
```

## License

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).