Values don't get saved to the database when fields are wrapped in a container When I wrap a field in a container, the field value doesn't get saved to the database. But if it lives in root, it works properly.

public function formElement(
  FieldItemListInterface $items,
  $delta,
  array $element,
  array &amp;$form,
  FormStateInterface $form_state
) {

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

    /** a bunch of fields **/

    $element['concelhocontainer'] = [
      '#type' =&gt; 'container',
      '#attributes' =&gt; ['id' =&gt; 'concelhocontainer']
    ];

    /** works properly **/
    $element['concelho'] = [
      '#type' =&gt; 'select',
      '#title' =&gt; t('County'),
      '#default_value' =&gt; isset($item-&gt;concelho) ? $item-&gt;concelho : '',
      '#options' =&gt; $this-&gt;getConcelhoList()
    ];

  /** does not work
  $element['concelhocontainer']['concelho'] = [
    '#type' =&gt; 'select',
    '#title' =&gt; t('County'),
    '#default_value' =&gt; isset($item-&gt;concelho) ? $item-&gt;concelho : '',
    '#options' =&gt; $this-&gt;getConcelhoList()
  ];
  */
  return $element;
}


The problem is that the value of the second input is not saved to the database (I've confirmed it in the database).
It seems Drupal adds a #tree = true property to the field parent so you need to process the data output by the form youserlf or the form nested elements will be ignored. As @IvanJaros poited out, WidgetBase::massageFormValues let's you alter the data.

public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
{
  for ($i=0; $i &lt; count($values); ++$i) {
    if (isset($values[$i]['concelhocontainer']['concelho'])) {
      $values[$i]['concelho'] = $values[$i]['concelhocontainer']['concelho'];
    }
  }
  return $values;
}