An implementation of a custom selection adapter for the Select2 plugin (v4) - multiple mode. Displays the selected tags into a separate section, leaving the search box empty.
https://andreivictor.github.io/select2-customSelectionAdapter/.
Initialize the select2 plugin with the selectionAdapter
option.
var CustomSelectionAdapter = $.fn.select2.amd.require("select2/selection/customSelectionAdapter");
$("select").select2({
// options
selectionAdapter: CustomSelectionAdapter
});
Include the script after Select2 main javascript file:
<script src="select2.js"></script>
<script src="select2.customSelectionAdapter.min.js"></script>
Include the css file:
<link rel="stylesheet" href="select2.customSelectionAdapter.css" />
By default, the tags are added immediately after the select2
container.
You can use the selectionContainer
option to add them somewhere else in the page.
var CustomSelectionAdapter = $.fn.select2.amd.require("select2/selection/customSelectionAdapter");
$("select").select2({
// options
selectionAdapter: CustomSelectionAdapter,
selectionContainer: $('.foo')
});
- Select2 4+
The license is available within the repository in the LICENSE file.