6.6. Select2 Loader

Initializes select2 on the given <select> element. It does no more than run the $.select2() method. It is possible to initialize the widget with default or custom options.

JavaScript Required

Script `select2-loader.js` and **select2 package** must be included.

Usage

This loader only calls the jQuery plugin defined in the select2 library with appropriate arguments. The select2 component natively uses the lang attribute of any parent element, so just be sure to include the correct locale file.

Data-API

If a <select> element has the attribute data-onload-select2 defined, it will be initialized as a select2 upon page load. The widget can be configured by the value passed to the attribute. If no value is passed, then select2 is initiated with default configuration. If a JSON object is passed, then it will be parsed and used as a configuration object (see https://select2.github.io/options.html for supported options).