Drupal - How to hide default "N/A" option for checkboxes?

You can use jQuery to accomplish this

$("#edit-field-gender-und-none").remove();

I think a better way to acheive this would be to write a simple form_alter hook and unset() the option you don want from your field.

function YOURMOD_form_YOURFORM_alter(&$form, &$form_state) {
  unset($form['YOURFIELD']['und']['#options']['_none']);
}

in the example above, the field is a taxonomy reference field on an entity edit form, so there is the extra ['und'] - it doesnt have to be there under all ocasions. You may want to dpm($form) first, to see the structure of the form.


Another quick solution is to have Drupal add a form-disabled class to the N/A form-item by adding the following function to your template.php file.

function <theme_name>_form_element($variables) {
  $element = $variables['element'];
  // Disable radio button N/A
  if ($element['#type'] == 'radio' && $element['#return_value'] === '_none') {
    $variables['element']['#attributes']['disabled'] = TRUE;
  }
  return theme_form_element($variables);
}

Then you can use CSS to do

.form-radios .form-disabled {
  display: none;
}

Tags:

Forms

Theming

7