You are here

function hook_select2_element_alter in Select 2 7

Alter the form element processed by Select2 module.

This hook is called before element select2 setting stored in $element['#select2'] key, will be added to global js settings array.

Parameters

$element: A renderable array representing the form element processed by Select2 process functions.

See also

select2_process_textfield()

select2_select_element_process()

2 invocations of hook_select2_element_alter()
select2_process_textfield in ./select2.module
Process textfield.
select2_select_element_process in ./select2.module
Select element process.

File

./select2.api.php, line 21
Hooks provided by the Select2 module.

Code

function hook_select2_element_alter(&$element) {

  // Change width option value.
  $element['#select2']['width'] = 'auto';

  // Add a new custom_option with specific value.
  $element['#select2']['new_custom_option'] = 'new_custopm_option_value';
}