Integrates Drupal autocomplete and select fields with the Select2 jQuery library.
After installing Select2 module you can attach Select2 plugin for all selects form elements (on front-end pages and admin pages, if needed) by defining settings on Select2 module config page, you can also define exludion rules for disabling Select2 plugin attaching for some elements by:
- CSS classes,
- jQuery selector rules.
For attaching Select2 plugin to form element by Forms API you must define #select2 attribute in element array.
'products_categories' => array( '#title' => t('Element title'), '#type' => 'select', '#options' => array(), '#empty_option' => t('Select element'), '#multiple' => 1, '#select2' => array(), ),
Code abowe will atach Select2 plugin for select element with default properties values, in '#select2' array you can define all properties from Select2 documentation, that accepts non-function value (string, int, object etc):
... '#select2' => array( 'width' => '150', 'placeholder' => 'Placeholder text', 'allowClear' => TRUE, ... ), ...
Also you can individually enable Select2 attaching for fields by setting options in "SELECT2 INTEGRATION SETTINGS" fieldset (if it available for current field) on field configuration page.
- Libraries (7.x-2.1 or higher)
- jQuery >= 1.7.2
Install (or update if needed) and/or enable:
- libraries (7.x-2.1 or higher) module
Download Select2 plugin (3.5.4) and extract it to sites/all/libraries/select2, you can use drush command "select2-download" for downloading Select2 plugin from repository:
for download Select2 3.5.4 version and store it to sites/all/libraries/select2
drush select2-download --tag=master
for download Select2 from curent master branch
You can define custom settings on admin/config/user-interface/select2integration_settings page.
Select2 branch 4.x isn't yet supported.
Please use 3.5.4 version of Select2 plugin - https://github.com/select2/select2/releases/tag/3.5.4
- This project is developed by IM.
- Maintenance status: Actively maintained
- Development status: Under active development
- Reported installs: 1,972 sites currently report using this module. View usage statistics.
- Downloads: 7,649
- Last modified: June 25, 2016
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.