selectize.js
Selectize is the hybrid of a textbox and <select> box. It's jQuery based, and it has autocomplete and native-feeling keyboard navigation; useful for tagging, contact lists, etc.
Top Related Projects
Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Simple autocomplete pure vanilla Javascript library.
A vanilla JS customisable select box/text input plugin ⚡️
Quick Overview
Selectize.js is a powerful and feature-rich JavaScript plugin that combines the functionality of select boxes and text inputs. It offers an intuitive interface for searching, sorting, and managing large lists of options, making it ideal for creating customizable dropdown menus, tags, and contact lists.
Pros
- Highly customizable with numerous options and themes
- Supports both single and multiple selections
- Offers keyboard navigation and accessibility features
- Integrates well with popular frameworks like Bootstrap and jQuery
Cons
- Can be resource-intensive for very large datasets
- Learning curve for advanced customization
- Occasional compatibility issues with older browsers
- Dependency on jQuery (though a vanilla JS version is in development)
Code Examples
Creating a basic single-select dropdown:
$('#select-beast').selectize({
create: true,
sortField: 'text'
});
Implementing a multiple-select with tags:
$('#select-tags').selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
Custom rendering of options:
$('#select-movie').selectize({
valueField: 'id',
labelField: 'title',
searchField: ['title', 'year'],
options: movies,
render: {
option: function(item, escape) {
return '<div>' +
'<span class="title">' + escape(item.title) + '</span>' +
'<span class="year">(' + escape(item.year) + ')</span>' +
'</div>';
}
}
});
Getting Started
- Include the necessary files in your HTML:
<link rel="stylesheet" href="selectize.css">
<script src="jquery.js"></script>
<script src="selectize.js"></script>
- Create a select element in your HTML:
<select id="my-select">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
- Initialize Selectize on your select element:
$(document).ready(function() {
$('#my-select').selectize();
});
This will transform your standard select element into a Selectize dropdown with enhanced functionality and styling.
Competitor Comparisons
Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
Pros of Chosen
- Simpler implementation and easier to set up for basic use cases
- Lighter weight with a smaller file size
- Better browser compatibility, especially for older versions
Cons of Chosen
- Less flexible and customizable compared to Selectize
- Fewer advanced features like remote data loading and tagging
- Not actively maintained (last update in 2018)
Code Comparison
Chosen initialization:
$(".chosen-select").chosen({
disable_search_threshold: 10,
no_results_text: "Oops, nothing found!",
width: "95%"
});
Selectize initialization:
$('select').selectize({
create: true,
sortField: 'text',
plugins: ['remove_button'],
render: {
option: function(item, escape) {
return '<div>' + escape(item.text) + '</div>';
}
}
});
Both libraries aim to enhance HTML select elements, but Selectize offers more advanced features and customization options. Chosen is simpler to implement and lighter, making it suitable for basic use cases. However, Selectize provides more flexibility for complex scenarios, including tagging, remote data, and custom rendering. The code comparison shows that Selectize requires more configuration but offers greater control over the select element's behavior and appearance.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
Pros of Select2
- More extensive documentation and examples
- Larger community and more frequent updates
- Better support for RTL languages and accessibility features
Cons of Select2
- Larger file size and potentially slower performance
- Less flexible for custom styling and advanced customization
- Steeper learning curve for complex implementations
Code Comparison
Selectize.js:
$('select').selectize({
create: true,
sortField: 'text'
});
Select2:
$('select').select2({
tags: true,
sorter: data => data.sort((a, b) => a.text.localeCompare(b.text))
});
Both libraries offer similar functionality for creating searchable and customizable select inputs. Selectize.js tends to have a more straightforward API for basic use cases, while Select2 provides more advanced features out of the box.
Select2 is generally considered more suitable for large-scale projects with complex requirements, while Selectize.js may be preferred for simpler implementations or when a smaller file size is crucial.
Ultimately, the choice between these libraries depends on the specific needs of your project, including factors such as required features, performance considerations, and the level of customization needed.
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Pros of Sortable
- More versatile, supporting drag-and-drop functionality for various UI elements
- Lightweight and dependency-free, making it easier to integrate
- Active development with frequent updates and bug fixes
Cons of Sortable
- Lacks built-in search and filtering capabilities
- Does not provide advanced select/dropdown functionality out of the box
- May require additional plugins or custom code for complex use cases
Code Comparison
Selectize.js (creating a sortable select):
$('#select-beast').selectize({
create: true,
sortField: 'text'
});
Sortable (creating a sortable list):
new Sortable(document.getElementById('list'), {
animation: 150,
ghostClass: 'blue-background-class'
});
Key Differences
Selectize.js is primarily focused on enhancing select inputs with search, tagging, and sorting capabilities. It's ideal for creating user-friendly dropdown menus and tag inputs.
Sortable, on the other hand, is a more general-purpose library for adding drag-and-drop functionality to various HTML elements. It's better suited for creating sortable lists, grids, and other UI components that require reordering.
While both libraries can handle sorting, they serve different primary purposes. Selectize.js excels in select input enhancements, while Sortable shines in drag-and-drop interactions across different UI elements.
Simple autocomplete pure vanilla Javascript library.
Pros of autoComplete.js
- Lightweight and dependency-free, resulting in faster load times
- Modern ES6+ syntax, making it easier to integrate with contemporary JavaScript projects
- Extensive customization options for styling and behavior
Cons of autoComplete.js
- Less mature ecosystem compared to Selectize.js
- Fewer built-in features, potentially requiring more custom development
- Limited support for older browsers due to modern JavaScript syntax
Code Comparison
autoComplete.js:
const autoCompleteJS = new autoComplete({
selector: "#autoComplete",
data: {
src: ["Apple", "Banana", "Cherry"],
cache: true,
},
resultsList: {
element: (list, data) => {
if (!data.results.length) {
const message = document.createElement("div");
message.setAttribute("class", "no_result");
message.innerHTML = `<span>Found No Results for "${data.query}"</span>`;
list.prepend(message);
}
},
noResults: true,
},
});
Selectize.js:
$('#select-beast').selectize({
create: true,
sortField: 'text',
options: [
{value: 'apple', text: 'Apple'},
{value: 'banana', text: 'Banana'},
{value: 'cherry', text: 'Cherry'}
]
});
Both libraries offer autocomplete functionality, but autoComplete.js provides a more modern approach with native JavaScript, while Selectize.js relies on jQuery and offers a more traditional select-based interface.
A vanilla JS customisable select box/text input plugin ⚡️
Pros of Choices
- More modern codebase with TypeScript support
- Better accessibility features out of the box
- Smaller bundle size and improved performance
Cons of Choices
- Less extensive plugin ecosystem
- Fewer customization options for advanced use cases
- Limited support for older browsers compared to Selectize
Code Comparison
Selectize:
$('select').selectize({
create: true,
sortField: 'text'
});
Choices:
const element = document.querySelector('select');
const choices = new Choices(element, {
allowHTML: false,
searchEnabled: true,
removeItemButton: true
});
Both libraries offer similar functionality for creating enhanced select inputs, but Choices uses a more modern JavaScript approach with class instantiation, while Selectize relies on jQuery-style initialization.
Choices provides a cleaner API with more intuitive options, making it easier for developers to get started quickly. However, Selectize offers more advanced features and flexibility for complex use cases, albeit with a steeper learning curve.
Overall, Choices is a solid choice for modern web applications prioritizing performance and accessibility, while Selectize remains a powerful option for projects requiring extensive customization and compatibility with older systems.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
selectize.js
â Selectize is looking for new members on the maintenance team!
Selectize is an extensible jQuery-based custom <select>
; UI control. It's useful for tagging, contact lists, country selectors, and so on. The goal is to provide a solid & usable experience with a clean and powerful API.
Features
- Smart Option Searching / Ranking Options are efficiently scored and sorted on-the-fly (using sifter). Want to search for an item's title and description? No problem.
- Caret between items Order matters sometimes. Use the ← and → arrow keys to move between selected items.
- Select & delete multiple items at once Hold down option on Mac or ctrl on Windows to select more than one item to delete.
- DÃÃ¥critîçs supported Great for international environments.
- Item creation Allow users to create items on the fly (async saving is supported; the control locks until the callback is fired).
- Remote data loading For when you have thousands of options and want them provided by the server as the user types.
- Clean API & code Interface with it and make modifications easily. Pull requests are always welcome!
- Extensible Plugin API for developing custom features (uses microplugin).
- Touch Support Plays nice with iOS 5+ devices.
Dependencies
- jquery (1.7 and greater), as peer dependency
- Note: it is installed automatically in development, or in projects using NPM 1 or 2. When using NPM from version 3 on, just a warning is thrown and the user needs to manually install an explicit version in their own project (e.g.
npm install --save jquery@3.5.1
).
- Note: it is installed automatically in development, or in projects using NPM 1 or 2. When using NPM from version 3 on, just a warning is thrown and the user needs to manually install an explicit version in their own project (e.g.
Optional:
- jquery-ui (required by
drag_drop
plugin)
Installation
Selectize can be installed via NPM npm install @selectize/selectize
Installing Manually
All pre-built files needed to use Selectize can be found in the "dist" folder.
If you're looking to get started with minimal fuss, include
selectize.min.js
(bundles Sifter and Microplugin
dependencies â also available un-minified for debugging, just remove the
.min
part) and css/selectize.default.css
.
Selectize is available at cdnjs.
- js/
- selectize.js â With dependencies, minus jquery
- selectize.min.js â With dependencies, minus jquery
- scss/ â Sass source files for customization (Bootstrap 3+ compatible)
- less/ â Less source files for customization (Bootstrap 2/3 compatible)
- css/
- selectize.css â Core styles
- selectize.default.css â Default theme (with core styles)
- selectize.bootstrap2.css - Bootstrap 2 theme
- selectize.bootstrap3.css - Bootstrap 3 theme
- selectize.bootstrap4.css - Bootstrap 4 theme
- selectize.bootstrap5.css - Bootstrap 5 theme
Usage
$("select").selectize(options);
The available options are documented here.
Contributing
When issuing a pull request:
-
please do not include/commit changes in the
dist/
orlib/
folders to avoid merge conflicts. A good way to include the right files is to usegit gui
orgit add
when committing to select the files you want to add to your commit. -
please include tests with your feature so that we're not tempted to break it in the future!
Add an entry to the top of the CHANGELOG, and update the documentation
in docs/
as needed. (Refactors and documentation changes don't need a
changelog entry.)
Squash your commits together in one or a few complete, logical commits, with a concise and descriptive message. One commit means one feature/bugfix/thing that has changed, or a diff bringing the code one step forward to a better, working state.
Once your commit is nice and clean, and you want to discard the other
changes, you can use git checkout .
(that will erase changes to
tracked files) and git clean [-i/--interactive]
(to erase untracked
files). However, be careful with those commands, as their function
is to erase things/changes.
However, be careful not to add the dist/
files in your commit, as
Grunt automatically regenerates the files in dist/
as the source is
changed.
Tests
Please ensure all the tests pass:
npm test # defaults to ChromHeadless
BROWSERS=Firefox npm test
BROWSERS=Firefox,Chrome npm test
BROWSERS=Firefox,Chrome,Safari npm test
Local environment
To run Selectize locally:
npm start
You can then run the examples at https://loopback.website:4000/
.
License
Copyright © 2013â2016 Brian Reavis & Contributors
Copyright © 2020-2022 Selectize Team & Contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Top Related Projects
Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Simple autocomplete pure vanilla Javascript library.
A vanilla JS customisable select box/text input plugin ⚡️
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot