In hook_form_alter()
, I am trying to disable/hide a field label in a custom form. I know I could use $form['my_field']['#enableLabel'] = FALSE;
.
Is there a way without unsetting the title?
In hook_form_alter()
, I am trying to disable/hide a field label in a custom form. I know I could use $form['my_field']['#enableLabel'] = FALSE;
.
Is there a way without unsetting the title?
Unsetting not really, hide yes : use #title_display and its get accessible to screenreader :
$form['my_field']['#title_display'] = 'invisible';
$form['my_field']['widget']['#title_display'] = 'invisible';
– William Turrell
Oct 31 '18 at 11:17
you can try:
function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['title']['widget']['0']['value']['#title_display']=none;
}
Note: change "title" by your machine name field.