You are here

function cck_select_other_widget in CCK Select Other 6

Implementation of hook_widget().

File

./cck_select_other.module, line 88
Implements a select list widget that lets a user provide an alternate option.

Code

function cck_select_other_widget(&$form, &$form_state, $field, $items, $delta = NULL) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => '',
  );
  $options = cck_select_other_options($field);
  if (empty($items)) {
    $items[] = array(
      'value' => '',
    );
  }
  if (!isset($options[$items[$delta]['value']])) {
    $def = 'other';
  }
  else {
    $def = $items[$delta]['value'];
  }
  $element['select_other_list'] = array(
    '#type' => 'select',
    '#title' => t(''),
    '#description' => t('Select other to enter your own option.'),
    '#options' => $options,
    '#default_value' => $def,
  );
  $element['select_other_text_input'] = array(
    '#type' => 'textfield',
    '#title' => t('Specify other'),
    '#default_value' => $def == 'other' ? check_plain($items[$delta]['value']) : '',
  );
  return $element;
}