This module allows us to sort the elements of a field which has the select list
We have a field called Months, which is a "List (text)" field with the "Select list" widget. In the "Allowed values list" for this field we have the following values:
In the "
SORT OPTIONS" fieldset:
- Check "
Apply sort option";
- Choose "
Order by" - order by text or by the selected value;
Explanation: If we will inspect (using FireBug or else) the Months element
from the form, we will have the following:
<select id="edit-field-months-und" name="field_months[und]"
<option value="_none">- None -</option>
Based on the code above, the "value" for an option will be "
and the text will be "
- None -".
- Choose "
Sort" - Ascending or Descending.
In our given form, we will be able to see the elements sorted by the chosen
Furthermore, it is possible to add 2 new attributes for the custom created
#sort_order" and "
#sort_order" - may contain values as "
asc" or "
#order_by" may contain values as "
text" or "
$form['selected_my_data'] = array(
'#type' => 'select',
'#title' => t('Selected Integer'),
'#options' => array(
'zero' => t('Zero'),
'one' => t('One'),
'seven' => t('Seven'),
'seven' => t('Six'),
'two' => t('Two'),
'#default_value' => 'nine',
'#order_by' => 'text', // May contain values as "text" or "value".
'#sort_order' => 'asc', // May contain values as "asc" or "desc".
As specified in the code above, the options for this element will be ordered by
text and ascendingly sorted.
For more details, please view this video: http://www.youtube.com/watch?v=7eYkUA28gvw
At the moment a select list with the "Check boxes/radio buttons" widget cannot be sorted.