The standard multiple select list can be difficult to use, if your users are not very technical. Most of the time they won’t know that you have to hold down command or ctrl key if you want to select multiple options. Also, once you have more than 10 options, the select list becomes very difficult to use. One wrong move and you can loose all the selected options.
The Multiselect module defines a widget that allows users to move selected items from one box to another. Visually this helps users to see which items have been selected. The widget can be used on a bunch of field types and it can be implemented as a form element using FAPI.
If you want to use Multiselect on an entity reference field, then use the 7.x-1.x-dev version.
Getting Started
Download and install the Multiselect module.
Configure Multiselect on Term Reference Field
In this section, we’ll use the Multiselect widget on the Tags field that is created when you install Drupal using the standard installation profile.
1. Structure -> “Content types” and click on “manage fields” within the Article row.
2. Click on Edit within the Tags row and then click on the “Widget tab” in the top right corner.
3. Select Multiselect from the “Widget type” select list and click on Continue.
4. Go to Content -> “Add content” and click on Article. Now the Tags widget has changed to a Multiselect widget.
Form API Multiselect Widget
You can also use the Multiselect widget on custom forms by defining '#type' => 'multiselect'
on a form element. Thankfully, the module ships with “Multiselect FAPI Example” module that shows you a working example.
1. Enable the “Multiselect FAPI Example” module.
2. Go to /multiselect_fapi_example
and you should see the example form.
Open the multiselect_fapi_example.module
file and go to multiselect_fapi_example_display()
. In this function you’ll see the multiselector
form element.
$form['multiselector'] = array(
'#type' => 'multiselect',
'#title' => t('Here is the multiselect'),
'#options' => array(
'title' => t('Titles only'),
'teaser' => t('Titles plus teaser'),
'fulltext' => t('Full text'),
'1' => t('Option 1'),
'2' => t('Option 2'),
),
'#default_value' => _multiselect_fapi_example_options(),
'#multiple' => TRUE,
'#size' => 15,
'#required' => TRUE,
);