Custom field widget form - Multiple values I've create a custom field form widget for an entity reference field. When only one value is allowed it shows a (filtered) select list, but I want to allow user to assign multiple reference values to that field. 

In my use case I want it to be shown as checkboxes when multiple values are allowed, but by default it shows my checkboxes in a 'add-another' fieldset.

How can this be accomplished? 

Below some code, $type is now a field setting and is manually set.

// Construct element
$widget = $element;
$widget['#delta'] = $delta;
$type = $settings['option_limit_type'];

... extra logic ...

switch ($type) {
      case 'select':
        $widget += array(
          '#type' =&gt; 'select',
          '#prefix' =&gt; '&lt;div id="' . $settings[$element['#field_name']]['ajax_wrapper'] . '"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
          '#options' =&gt; $options,
          '#delta' =&gt; $delta,
          '#element_validate' =&gt; array('_entityreference_hierachy_option_limit_validate'),
          '#default_value' =&gt;  $saved_target_id,
        );
        break;
      case 'checkboxes':
        $widget += array(
          '#type' =&gt; 'checkboxes',
          '#prefix' =&gt; '&lt;div id="' . $settings[$element['#field_name']]['ajax_wrapper'] . '"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
          '#options' =&gt; $options,
          '#delta' =&gt; $delta,
          '#element_validate' =&gt; array('_entityreference_hierachy_option_limit_validate'),
          '#default_value' =&gt;  $saved_target_id,
        );
        break;
    }
return $widget;
You can use drupal form api attributes like 



 case 'select':
        $widget += array(
          '#type' =&gt; 'select',
          '#prefix' =&gt; '&lt;div id="' . $settings[$element['#field_name']]['ajax_wrapper'] . '"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
          '#options' =&gt; $options,
          '#delta' =&gt; $delta,
          '#element_validate' =&gt; array('_entityreference_hierachy_option_limit_validate'),
          '#default_value' =&gt;  $saved_target_id,
          '#multiple' =&gt; $multiple,
          '#size' =&gt; $multiple ? min(12,count($options)) : 0, 
        );
        break;




https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#multiple