Drupal - Rename "-none-" option for select list field type

Implement hook_form_alter() or hook_form_FORM_ID_alter() and use the following code:

$form['field_name'][LANGUAGE_NONE]['#options']['_none'] = t('Select');

example:

function MODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
    $form['field_name'][LANGUAGE_NONE]['#options']['_none'] = t('Select');
}

The t() function is for translation. It may not be required, but it is good practice to use instead of hard-coded strings.

To remove - None - as a choice all together, you could unset the key using hook_form_alter as well.

example:

function MODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
    unset($form['field_name'][LANGUAGE_NONE]['#options']['_none']);
}

If you're not using it already, be sure to install the Devel module so you have access to the dpm() and dd() functions. They are incredibly valuable when playing with Drupal forms.


You can override the theme_options_none theme function. Follow the example from the Drupal API. If you want to replace "- None -" with "- Select -" everywhere, this theme implementation should do the trick:

/**
 * Returns HTML for the label for the empty value for options that are not required.
 *
 * The default theme will display N/A for a radio list and '- None -' for a select.
 *
 * @param $variables
 *   An associative array containing:
 *   - instance: An array representing the widget requesting the options.
 *
 * @ingroup themeable
 */
function MYTHEMENAME_options_none($variables) {
  return t('- Select -');
}

Place this function in your theme's template.php.


If you already have some jquery/javascript included in your system, eg a custom theme or module, you can add something like:

$('select option:contains("- None -")').text("- Select -");

and it will change it up for you. You can cascade more in there if you want to be specific to just a certain select/option as the above will change all of them.

Otherwise, on the php side of things, the - None - is passed through t('- None -') so you could use one of the many localize or customtext modules to change the text, but this would be systemwide as well.

Tags:

Entities