On April 12, 2020 . By CodimTh Category: Web Drupal In this post, I'll show you how to set a form field as read only or disabled in Drupal 8. To set field name as readonly: $form['name']['#attributes'] = array('readonly' => 'readonly'); To set field name as disabled: $form['name']['#attributes'] = array('disabled' => 'disabled'); Tags : Drupal 8 Snippets Form API Previous PostDrupal 8 - Reset button not working in the webform after form submitNext PostAdd reset button to forms in Drupal 8 Comments Submitted by Gaetano Leoni (not verified) on Mon, 04/13/2020 - 08:40 Permalink Where do I write the code Should the code you indicated be written in hook_form_alter? Reply Submitted by codimth on Mon, 04/13/2020 - 10:08 Permalink Yes in hook_form_alter or in… Yes in hook_form_alter or in buildForm() if you want to create custom form. Reply Add new comment Your name Subject Comment About text formats Restricted HTML Leave this field blank
Submitted by Gaetano Leoni (not verified) on Mon, 04/13/2020 - 08:40 Permalink Where do I write the code Should the code you indicated be written in hook_form_alter? Reply
Submitted by codimth on Mon, 04/13/2020 - 10:08 Permalink Yes in hook_form_alter or in… Yes in hook_form_alter or in buildForm() if you want to create custom form. Reply
Comments
Where do I write the code
Yes in hook_form_alter or in…
Yes in hook_form_alter or in buildForm() if you want to create custom form.