In a custom Drupal 8 module, I have a couple of Form API fields of '#type' => 'select'
:
$form['form-right']['field_role'] = [
'#type' => 'select',
'#title' => $this->t('Role'),
'#title_display' => 'invisible',
'#required' => TRUE,
'#options' => [
'foo' => $this->t('Role Foo'),
'bar' => $this->t('Role Bar'),
'baz' => $this->t('Role Baz'),
'quux' => $this->t('Role Quux'),
'plugh' => $this->t('Role Plugh'),
'xyzzy' => $this->t('Role Xyzzy'),
],
'#attributes' => [
'placeholder' => $this->t('Role'),
],
];
$form['form-right']['field_contact_reason'] = [
'#type' => 'select',
'#title' => $this->t('Contact Reason'),
'#title_display' => 'invisible',
'#required' => TRUE,
'#options' => [
'foo' => $this->t('Contact Reason Foo'),
'bar' => $this->t('Contact Reason Bar'),
'baz' => $this->t('Contact Reason Baz'),
'other' => $this->t('Other'),
],
'#attributes' => [
'placeholder' => $this->t('Contact Reason'),
],
];
Before a value is selected, the dropdown select picklists display the string '- Select -'
:
The client would like them to display the value in the placeholder attribute instead.
Have I done something wrong?