{"_id":"multi-select-dropdown-js","_rev":"2-87d3890344b322b9e0d2b98d1bff96a5","name":"multi-select-dropdown-js","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.3":{"name":"multi-select-dropdown-js","version":"1.0.3","keywords":["select","multi-select","dropdown","vanilla-js","no-jquery","optgroup","form-validation"],"author":{"url":"https://codeshack.io","name":"David Adams","email":"info@codeshack.io"},"license":"MIT","_id":"multi-select-dropdown-js@1.0.3","maintainers":[{"name":"codeshackio","email":"info@codeshack.io"}],"homepage":"https://codeshack.io/multi-select-dropdown-html-javascript/","bugs":{"url":"https://github.com/codeshackio/multi-select-dropdown-js/issues"},"dist":{"shasum":"8b40ef11b24a311fe1e188cbf3fa57af785eee4c","tarball":"https://registry.npmjs.org/multi-select-dropdown-js/-/multi-select-dropdown-js-1.0.3.tgz","fileCount":7,"integrity":"sha512-9eX3CAtjzSwvFiwmay6+xCbnmCGlG+F/HbhvFyu5LTXc1sMWpbRqPhjzd6XUsTefn+iMFfrgS5I6MdFwfxQtIQ==","signatures":[{"sig":"MEQCIFBymbnJa9QBeDH3vYgwW7999nrdvGYWOtyZAbh98uAXAiBmWa3ZQh8Rs0Jre+SOVjtV+OI/f6r8Ggfz8B58Ba416g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":80052},"main":"MultiSelect.js","style":"MultiSelect.min.css","unpkg":"MultiSelect.min.js","_npmUser":{"name":"codeshackio","email":"info@codeshack.io"},"jsdelivr":"MultiSelect.min.js","repository":{"url":"git+https://github.com/codeshackio/multi-select-dropdown-js.git","type":"git"},"_npmVersion":"11.11.0","description":"A lightweight, dependency-free Multi Select Dropdown in Vanilla JavaScript.","directories":{},"_nodeVersion":"24.14.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/multi-select-dropdown-js_1.0.3_1774632048375_0.2594754834401978","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"_id":"multi-select-dropdown-js@1.0.4","bugs":{"url":"https://github.com/codeshackio/multi-select-dropdown-js/issues"},"dist":{"shasum":"ae1713f44597d722ff98a98a882c3ef04b5ada53","tarball":"https://registry.npmjs.org/multi-select-dropdown-js/-/multi-select-dropdown-js-1.0.4.tgz","fileCount":7,"integrity":"sha512-jhfhuQnlPJqZQzy1rCVGUhMs6w7l7iXvD5HorUzvgLRSyemQQwQFw/sOV1JcZIpojYpIpffhwOVl4iPU12rubg==","signatures":[{"sig":"MEQCIHGCWKQHSZp/NCB46ViGHrxYI89iqEhS8tc8+DoQiPjMAiBCIpHHfVFYM6jU6BXXDFvYOqZ7OWy7Wh/uH4PVMhSwaQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCpyllHReBSERJ/YwreSlvUtWdg3wkfqLi+Ffq2Hld9RQIgVu1NrI6IFLgQrKPZvyWZAx/+X4QM2PSGM+ztsae7tKs="}],"unpackedSize":84129},"main":"MultiSelect.js","name":"multi-select-dropdown-js","style":"MultiSelect.min.css","unpkg":"MultiSelect.min.js","author":{"url":"https://codeshack.io","name":"David Adams","email":"info@codeshack.io"},"gitHead":"d819a5e3d48f93e55334d1f9c3f4e348952ce603","license":"MIT","version":"1.0.4","_npmUser":{"name":"codeshackio","email":"info@codeshack.io"},"homepage":"https://codeshack.io/multi-select-dropdown-html-javascript/","jsdelivr":"MultiSelect.min.js","keywords":["select","multi-select","dropdown","vanilla-js","no-jquery","optgroup","form-validation"],"repository":{"url":"git+https://github.com/codeshackio/multi-select-dropdown-js.git","type":"git"},"_npmVersion":"11.11.0","description":"A lightweight, dependency-free Multi Select Dropdown in Vanilla JavaScript.","directories":{},"maintainers":[{"name":"codeshackio","email":"info@codeshack.io"}],"_nodeVersion":"24.14.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/multi-select-dropdown-js_1.0.4_1795475505497_0.3602417382563683"}}},"time":{"created":"2026-03-27T17:20:48.374Z","modified":"2026-11-23T23:11:45.769Z","1.0.3":"2026-03-27T17:20:48.525Z","1.0.4":"2026-11-23T23:11:45.588Z"},"bugs":{"url":"https://github.com/codeshackio/multi-select-dropdown-js/issues"},"author":{"url":"https://codeshack.io","name":"David Adams","email":"info@codeshack.io"},"license":"MIT","homepage":"https://codeshack.io/multi-select-dropdown-html-javascript/","keywords":["select","multi-select","dropdown","vanilla-js","no-jquery","optgroup","form-validation"],"repository":{"url":"git+https://github.com/codeshackio/multi-select-dropdown-js.git","type":"git"},"description":"A lightweight, dependency-free Multi Select Dropdown in Vanilla JavaScript.","maintainers":[{"name":"codeshackio","email":"info@codeshack.io"}],"readme":"# Multi Select Dropdown JS\n\n[![npm version](https://badge.fury.io/js/multi-select-dropdown-js.svg)](https://www.npmjs.com/package/multi-select-dropdown-js)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\nCreate powerful user interfaces with our **Multi Select Dropdown**! This tool enhances native select elements, allowing for multiple selections, dynamic content generation, integrated search functionality, and customizable UI without any dependencies. No jQuery or other library is required!\n\n**Complete Guide & Reference:** [https://codeshack.io/multi-select-dropdown-html-javascript/](https://codeshack.io/multi-select-dropdown-html-javascript/)  \n**Interactive Demo:** [https://codeshack.io/multi-select-dropdown-js/](https://codeshack.io/multi-select-dropdown-js/) \n\n## Features\n- **Multiple Selections**: Users can select more than one option in the dropdown.\n- **OptGroups & Sublists**: Natively parses HTML `<optgroup>` tags and automatically generates master toggle switches for groups.\n- **Native Form Validation**: Fully supports the HTML5 `required` attribute with perfectly positioned browser tooltips.\n- **Dark Mode & Themes**: Built-in support for `auto` (follows OS preference), `light`, and `dark` themes.\n- **Async Data Fetching**: Easily load external JSON arrays from APIs using the built-in `.fetch()` method.\n- **Search Functionality**: Includes a built-in search to find options quickly.\n- **Dynamic & Reactive**: Update options dynamically via JS setters. The UI instantly reacts to data changes.\n- **Secure & Accessible**: Built-in XSS protection, memory-leak proof, framework-agnostic, and fully keyboard navigable.\n- **Lightweight**: Lightweight in size and does not depend on other libraries.\n\n## Screenshot\n\n![Screenshot of Multi Select Dropdown](assets/screenshot.png)\n\n## Installation\n\nYou can integrate the library into your project using NPM, a CDN, or by downloading the files manually.\n\n### Option 1: NPM (Recommended)\nInstall the package via npm:\n```bash\nnpm install multi-select-dropdown-js\n```\nThen, import the CSS and JS into your project:\n```javascript\nimport 'multi-select-dropdown-js/MultiSelect.min.css';\nimport 'multi-select-dropdown-js/MultiSelect.min.js';\n```\nSelects with the `data-multi-select` attribute are converted automatically. To create instances in your own code, import the class instead:\n```javascript\nimport 'multi-select-dropdown-js/MultiSelect.min.css';\nimport MultiSelect from 'multi-select-dropdown-js';\n\nnew MultiSelect('#example-multi-select', { placeholder: 'Select options' });\n```\n\n### Option 2: CDN (jsDelivr)\nFor rapid prototyping or classic HTML workflows, include the minified files directly via jsDelivr.\n\nAdd the CSS to your `<head>` tag:\n```html\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/multi-select-dropdown-js/MultiSelect.min.css\">\n```\nAdd the JavaScript in your `<head>` or just before your closing `</body>` tag:\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/multi-select-dropdown-js/MultiSelect.min.js\"></script>\n```\n\n### Option 3: Manual Download\nClone the repository or download the ZIP, and include the files in your project:\n```html\n<link rel=\"stylesheet\" href=\"path/to/MultiSelect.min.css\">\n<script src=\"path/to/MultiSelect.min.js\"></script>\n```\n\n## Usage\n\nHere's a simple example to add the multi-select dropdown to your project. \n\n*(Tip: Always append `[]` to your `name` attribute if you are submitting data to a backend like PHP!)*\n\nEach option value should be unique within a list, because the selection and the submitted form data are matched by value.\n\n**Method A: Pure HTML Data Attributes**\n```html\n<select id=\"example-multi-select\" name=\"options[]\" data-placeholder=\"Select options\" multiple data-multi-select>\n    <option value=\"option1\">Option 1</option>\n    <option value=\"option2\">Option 2</option>\n    <!-- more options -->\n</select>\n```\n\n**Method B: JavaScript Initialization**\n```html\n<select id=\"example-multi-select\" name=\"options[]\" multiple>\n    <option value=\"option1\">Option 1</option>\n    <option value=\"option2\">Option 2</option>\n    <!-- more options -->\n</select>\n\n<script>\n    new MultiSelect('#example-multi-select', {\n        placeholder: 'Select options',\n        theme: 'auto'\n    });\n</script>\n```\n\n## Configuration\n\nYou can pass a settings object to customize the dropdown behavior and styling:\n\n```javascript\nnew MultiSelect('#example-multi-select', {\n    placeholder: 'Select options',\n    theme: 'auto', // 'auto', 'light', or 'dark'\n    min: 1,  // Minimum number of items required\n    max: 5,  // Maximum number of items that can be selected\n    search: true,  // Enable the search box\n    selectAll: true,  // Add a \"Select All\" toggle\n    listAll: true, // If false, shows \"X selected\" instead of listing tags\n    closeListOnItemSelect: false, // Auto-close the dropdown after selection\n    required: true, // Enforce native HTML5 form validation\n    \n    onChange: function(value, text, element) {\n        console.log('Change:', value, text, element);\n    },\n    onSelect: function(value, text, element) {\n        console.log('Selected:', value, text, element);\n    },\n    onUnselect: function(value, text, element) {\n        console.log('Unselected:', value, text, element);\n    },\n    onMaxReached: function(max) {\n        console.log('Maximum selections reached:', max);\n    }\n});\n```\n\n### Dynamically Adding Options & Groups\n\nYou can dynamically populate the dropdown with grouped data, disabled options, and safe custom HTML injection:\n\n```javascript\nconst mySelect = new MultiSelect('#example-multi-select', {\n    data:[\n        {\n            value: 'opt1',\n            text: 'Option 1',\n            group: 'Basic Settings'\n        },\n        {\n            value: 'opt2',\n            html: '<strong style=\"color: red;\">Option 2 with HTML!</strong>',\n            group: 'Basic Settings'\n        },\n        {\n            value: 'opt3',\n            text: 'Option 3',\n            selected: true,\n            group: 'Advanced Settings'\n        },\n        {\n            value: 'opt4',\n            text: 'Locked Option',\n            disabled: true // Prevents user interaction\n        }\n    ],\n    placeholder: 'Select options',\n    search: true,\n    selectAll: true\n});\n```\n\n### Asynchronous Data Fetching\n\nLoading data from a remote endpoint is handled natively:\n\n```javascript\nconst asyncSelect = new MultiSelect('#example-multi-select', {\n    placeholder: 'Loading remote data...'\n});\n\n// Fetches a JSON array formatted like the data object above\nasyncSelect.fetch('https://api.yoursite.com/endpoint');\n```\n\n## Changelog\n\n### 1.0.4\n- Selected items in the header now appear in the same order as the list. They were shown in reverse.\n- The script now works when it's loaded in the `<head>` without `defer`. Selects with `data-multi-select` are converted once the page has loaded, and loading it before `</body>` works as before.\n- \"Select all\" and group headers now work on a filtered list. The first click selects the items that match the search, the second click unselects them, and items outside the search keep their state. Their checkmarks follow the matching items.\n- Calling `destroy()` before the page has finished loading is no longer undone by the automatic setup, and one element that fails to convert no longer stops the rest.\n- The file can now be imported with a bundler or `require()`d (`module.exports`), and loading it where there is no `document` no longer throws.\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Contact\n\nDavid Adams - [info@codeshack.io](mailto:info@codeshack.io)\n\nGitHub: [https://github.com/codeshackio/multi-select-dropdown-js](https://github.com/codeshackio/multi-select-dropdown-js)\n\nX (Twitter): [https://twitter.com/codeshackio](https://twitter.com/codeshackio)\n\nFeel free to open an issue or submit pull requests.\n","readmeFilename":"README.md"}