Hi,

I want to change my entity_reference field from autocomplete to dropdown list (select). So far I try another method by overriding in buildForm method in my form class but it produce the error (Error: Cannot unset string offsets in Drupal\Core\Field\WidgetBase->extractFormValues()). Here is my code.

$form['account_group'] = [
  '#title' => $this->t('Account group'),
  '#description' => $this->t('The account group.'),
  '#type' => 'select',
  '#options' => $options,
  '#required' => TRUE,
  '#default_value' => $current_account_group,
];

I know that's not the good practice. What is the best way to do it? Maybe I should do it in my baseFieldDefinitions method. But I have no idea how to set it.

Comments

bogeyman’s picture

Arghh.. I was thinking too complicated. I can change it in form display :).