Custom widget not saving I've created a custom widget for a textarea (to display the contents in a table as well). So the textarea should appear and work just like a normal textarea widget, but with an additional HTML table of its contents.

I can make it appear correctly, but when I save the form the values do not get saved.

In fact, my "data_source_field_is_empty()" function is never called (the dpm() text never appears).

function data_source_field_widget_form(&amp;$form,
                                         &amp;$form_state,
                                         $field,
                                         $instance,
                                         $langcode,
                                         $items,
                                         $delta,
                                         $element) {
  switch ($instance['widget']['type']) {
    case 'data_source_data_widget':
      $thisItem = isset($items[$delta]) ? $items[$delta]['value'] : '';

      $widget['#type'] = 'textarea';
      $widget['#default_value'] = $thisItem;

      // Only do this if there is already content in the field
      if (isset($items[$delta])) {
        $rows = _data_source_parse_csv($thisItem);

        $widget['#prefix'] = '&lt;button type="button" id="show-hide-raw-table-data"&gt;Show raw data&lt;/button&gt;';
        $widget['#suffix'] = _data_source_dataTable($rows, 0);

        $form['#attached']['js'][] = array(
          'data' =&gt; drupal_get_path('module', 'data_source') . '/js/data_source.js',
          'type' =&gt; 'file',
        );
        $form['#attached']['css'][] = array(
          'data' =&gt; drupal_get_path('module', 'data_source') . '/css/data_source.css',
          'type' =&gt; 'file',
        );
      }

      $element[$field['field_name']] = $widget;
      break;

  }

  return ($element);
}

function data_source_field_is_empty($item, $field) {
  dpm("Got here");
  return empty($item[$field['field_name']]);
}


Any ideas? I'm looking at the $element[$field['field_name']] = $widget; part, but none of the variations I've tried have worked.
After studying the code in modules/field/text/text.module, I found the missing item: I had to assign my new widget to $element['value'], so:

$element['value'] = $widget;
return ($element);