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 &$form,
FormStateInterface $form_state
) {
$item =& $items[$delta];
$element += array(
#type' => 'fieldset',
);
/** a bunch of fields **/
$element['concelhocontainer'] = [
'#type' => 'container',
'#attributes' => ['id' => 'concelhocontainer']
];
/** works properly **/
$element['concelho'] = [
'#type' => 'select',
'#title' => t('County'),
'#default_value' => isset($item->concelho) ? $item->concelho : '',
'#options' => $this->getConcelhoList()
];
/** does not work
$element['concelhocontainer']['concelho'] = [
'#type' => 'select',
'#title' => t('County'),
'#default_value' => isset($item->concelho) ? $item->concelho : '',
'#options' => $this->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).