0

I am creating a custom field for phone numbers. The field creates a phone record that contains the type of phone contact (work, home, etc), as well as the number and an extension... much like Apple's "Contacts" app.

The problem I am having is for the phone type drop-down list. Instead of showing a nice drop-down select list like this example of a publishing status...

dropdown list

I end up with a selection box like this...

selection box

Here is what my hook_field_widget_info() looks like...

/**
 * Implements hook_field_widget_form().
 */
function MYMODULE_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

  $element['label'] = array(
    '#type' => 'select',
    '#options' => drupal_map_assoc(array(
      t('home'),
      t('work'),
      t('main'),
      t('mobile'),
      t('other'),
    )),
    '#size' => 12,
    '#default_value' => isset($items[$delta]['label']) ? $items[$delta]['label'] : 'home',
  );

  $element['number'] = array(
    '#type' => 'textfield',
    '#title' => t('Number'),
    '#size' => 16,
    '#default_value' => isset($items[$delta]['number']) ? $items[$delta]['number'] : '',
  );

  $element['ext'] = array(
    '#type' => 'textfield',
    '#field_prefix' => t('ext'),
    '#size' => 6,
    '#default_value' => isset($items[$delta]['ext']) ? $items[$delta]['ext'] : '',
  );

  $element['primary'] = array(
    '#type' => 'ckeckbox',
    '#default_value' => isset($items[$delta]['primary']) ? $items[$delta]['primary'] : 0,
    '#return_value' => 1,
  );

  return $element;
}

I can see how the selection box style select element can be useful for multiple selects, but this is just a single select. I'd like to see a drop-down element. I must be missing something here, but I haven't figured out what it could be. Any ideas?

1 Answer 1

1

Okay, I figured it out and it was much easier than I thought... It's the "size" attribute. I deleted the size attribute, ('#size' => 12,), and I have a drop-down select list. I suppose it just came to posting the question here for me to figure it out on my own. :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.