You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

select-unique

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

select-unique

Given a group of HTML select elements with the same options, Select Unique will remove an option from the other select elements when it's selected, and put it back when it's changed.

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Select Unique

Build Status

Given a group of HTML select elements with the same options, Select Unique will remove an option from the other select elements when it's selected, and put it back when it's changed.

Checkout the demo here.

Usage

Babel, webpack, etc...

npm install select-unique

Or:

yarn install select-unique

Then:

import SelectUnique from 'select-unique';

const selects = new SelectUnique('.some-group select');

You can also give it some HTMLSelectElements:

const elements = [
    document.querySelector('select:nth-of-type(2)'),
    document.querySelector('select:nth-of-type(4)')
]

const selects = new SelectUnique(elements);

Or even a NodeList:

const selects = new SelectUnique(document.querySelectorAll('select.question'));

If you want to ignore certain options:

const selects new SelectUnique(selector, {
    ignoreOption: option => option.value === 'ignore_me_buddy'
});

You can also retrieve what's currently selected or remaining within the group:

selects.remaining().forEach(option => {
    console.log(`text: ${option.text}  value: ${option.value}`);
});

selects.selected().forEach(option => {
    console.log(`text: ${option.text}  value: ${option.value}`);
});

Client-side

Include it in your html page (from jsdelivr or cdnjs):

<div id="my-select-group">
  <!-- A bunch of selects -->
</div>

<script src="https://cdn.jsdelivr.net/npm/select-unique@VERSION/dist/select-unique.min.js"></script>
<script>
  new SelectUnique('#my-select-group select');
</script>

Replace VERSION in the src URL with the desired version.

See Also

Author

Skye Shaw (skye.shaw -AT- gmail)

License

Released under the MIT License: http://www.opensource.org/licenses/MIT

Keywords

html

FAQs

Package last updated on 25 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts