How to create widget element with unlimited values? I have a widget for a field as shown below:



I would like to make the text field ('script_paths') an unlimited value so that the user can add as many as they like. Is there a way to do this? Maybe there is a property I add in my code below:

function mango_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {

  $field_name = $instance['field_name'];
  $required = $element['#required'];
  $item =&amp; $items[$delta];
  $element += array(
    '#type' =&gt; 'fieldset',
  );

  $element['enabled'] = array(
    '#title' =&gt; t('Enabled'),
    '#type' =&gt; 'checkbox',
    '#default_value' =&gt; isset($item['enabled']) ? $item['enbled'] : '',
  );

  $element['script_paths'] = array(
    '#title' =&gt; t('Script Paths'),
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; isset($item['script_paths']) ? $item['script_paths'] : '',
  );

  return $element;
}
I would think that there would be a property as well but I can't think of one for text fields. I know that you can use field collections though.

Edit: I was mistaken Field Collections will not work for custom forms, however This tutorial worked for me.