2.0.0 • Published 2 years ago

dual-listbox v2.0.0

Weekly downloads
2,733
License
MIT
Repository
github
Last release
2 years ago

Build Status Coverage Status Code Climate Lintly npm Known Vulnerabilities BCH compliance

NPM

Changes

Solves the duplicate option rendering problem, as mentioned in this issue https://github.com/maykinmedia/dual-listbox/issues/63

Dual Listbox

Make your multi select pretty and easy to use with only javascript. No other frameworks/libraries required.

Try the demo

Styling. (From the stylesheet that can be found in the dist folder)

Default

with selected options and one option highlighted.

selected

Install

Install with npm

$ npm i dual-listbox --save

CDN

<script src="https://cdn.jsdelivr.net/npm/dual-listbox/dist/dual-listbox.min.js"></script>
<link
    href="https://cdn.jsdelivr.net/npm/dual-listbox/dist/dual-listbox.css"
    rel="stylesheet"
/>

<!-- for pinned version -->
<script src="https://cdn.jsdelivr.net/npm/dual-listbox@1.0.9/dist/dual-listbox.min.js"></script>
<link
    href="https://cdn.jsdelivr.net/npm/dual-listbox@1.0.9/dist/dual-listbox.css"
    rel="stylesheet"
/>

Usage

let dualListbox = new DualListbox("select"); // Selects the first selectbox on the page.
let dualListbox = new DualListbox(".select"); // Selects the first element with the class 'select'
let dualListbox = new DualListbox("#select"); // Selects the first element with the id 'select'

let select = document.querySelector("#select");
let dualListbox = new DualListbox(select); // Add a HTMLElement

You can also pass some options to the DualListbox

let dualListbox = new DualListbox("#select", {
    addEvent: function (value) {
        // Should use the event listeners
        console.log(value);
    },
    removeEvent: function (value) {
        // Should use the event listeners
        console.log(value);
    },
    availableTitle: "Different title",
    selectedTitle: "Different title",
    addButtonText: ">",
    removeButtonText: "<",
    addAllButtonText: ">>",
    removeAllButtonText: "<<",

    sortable: true,
    upButtonText: "ᐱ",
    downButtonText: "ᐯ",

    draggable: true,

    options: [
        { text: "Option 1", value: "OPTION1" },
        { text: "Option 2", value: "OPTION2" },
        { text: "Selected option", value: "OPTION3", selected: true },
    ],
});

dualListbox.addEventListener("added", function (event) {
    console.log(event);
    console.log(event.addedElement);
});
dualListbox.addEventListener("removed", function (event) {
    console.log(event);
    console.log(event.removedElement);
});

Try it online on JSFiddle.

Exposed elements

All the elements should be exposed. This way it should be possible to add custom attributes to the element of choice.

let dualListbox = new DualListbox("#select");

// Access the buttons:
dualListbox.add_button.setAttribute("a", "a");
dualListbox.add_all_button.setAttribute("a", "a");
dualListbox.remove_button.setAttribute("a", "a");
dualListbox.remove_all_button.setAttribute("a", "a");

// Access the search field:
dualListbox.search_left.classList.add("some_class");
dualListbox.search_right.classList.add("some_class");

// Access the list containers:
dualListbox.selectedList.setAttribute("a", "a");
dualListbox.availableList.setAttribute("a", "a");

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Maykin Media

License

Copyright © 2019 Maykin Media Licensed under the MIT license.

abp-zero-templates-gabp-zero-template-gmanualabp-zero-templat-gabp-zero-template-g@infinitebrahmanuniverse/nolb-dua@everything-registry/sub-chunk-1535timothy.cruztimothy.cruz638timothy.cruz639sprintteksprinttek-cardssprinttek-dev-templatessprinttek-dev-templates-cardssprinttek-dev-templates-redsprinttek-redsprinttek-templatessprinttek-templates-1sprinttek-templates-cadssprinttek-templates-cardingsprinttek-templates-cardssprinttek-templates-jursprinttek-templates-namsprinttek-templates-nambriasprinttek-templates-redsprinttek-templates-yowsprinttek-templates0cardssprinttek-templatesssprinttek-templatessxsprinttek-templatesx1sprinttektestsprinttektest1chay-templateabp-zero-manualabp-zero-manual-publishabp-zero-sprinthubtestingabp-zero-sprinthubtesting2abp-zero-templat-cardsabp-zero-template-aabp-zero-template-ababp-zero-template-abcabp-zero-template-asdabp-zero-template-babp-zero-template-bcabp-zero-template-bcdabp-zero-template-bnmabp-zero-template-cabp-zero-template-cardingabp-zero-template-cardsabp-zero-template-cdabp-zero-template-pabp-zero-template-pcabp-zero-template-qwertyabp-zero-template-qwertyuabp-zero-template-qwertyuiabp-zero-template-rabp-zero-template-raraabp-zero-template-redabp-zero-template-redsabp-zero-template-reeseabp-zero-template-reesesabp-zero-template-reesesesabp-zero-template-resaabp-zero-template-resaaabp-zero-template-resaaaabp-zero-template-resaaaaabp-zero-template-cdeabp-zero-template-chayabp-zero-template-chay1abp-zero-template-cpabp-zero-template-dabp-zero-template-deabp-zero-template-defabp-zero-template-eabp-zero-template-efabp-zero-template-efgabp-zero-template-efraiabp-zero-template-fabp-zero-template-fgabp-zero-template-fghabp-zero-template-ghabp-zero-template-ghiabp-zero-template-habp-zero-template-hiabp-zero-template-hijabp-zero-template-hjkabp-zero-template-hubabp-zero-template-iabp-zero-template-ijabp-zero-template-ijbabp-zero-template-ijkabp-zero-template-jabp-zero-template-jkabp-zero-template-jklabp-zero-template-rstabp-zero-template-rweaabp-zero-template-sabp-zero-template-sadabp-zero-template-sdwabp-zero-template-stabp-zero-template-stu
2.0.0

2 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.4.0-alpha3

4 years ago

1.4.0-alpha2

4 years ago

1.4.0-alpha1

4 years ago

1.3.0

5 years ago

1.1.0

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

1.0.0

7 years ago