1

I'm trying to disable input fields of type date and checkbox in hook_form_alter with above code:

$key = 'field_name';

$form[$key]['widget'][0]['value']['#attributes']['disabled'] = true;
$form[$key]['widget']['#attributes']['disabled'] = true;
$form[$key]['widget'][0]['#attributes']['disabled'] = true;
$form[$key]['widget'][0]['target_id']['#attributes']['disabled'] = true;
$form[$key]['widget'][0]['#attributes']['disabled'] = true;
$form[$key]['#disabled'] = 'disabled';
$form[$key]['widget']['#attributes']['readonly'] = 'readonly';

Disabled all fields (type text or entity reference) but not work for checkbox and date fields. Any ideas for solve this?

1 Answer 1

0

This is how to disable the field:

$form[$key]['widget'][0]['value']['#attributes']['disabled'] = 'disabled';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.