Cannot affect the visibility or requirement of managed_file with states. Identical to #1118016: conditional visibility of a managed_file using #states attribute does not work → so either the bug wasn't fully fixed before, or a regression happened at some point and broke this functionality.
With this definition:
$form['type'] = [
'#type' => 'select',
'#options' => [
'node' => t('Content'),
'webform' => t('Webform'),
],
];
$form['webform'] = [
'#type' => 'select',
'#title' => t('Webform reference'),
'#states' => [
'visible' => [':input[name="type"]' => ['value' => 'webform']],
'required' => [':input[name="type"]' => ['value' => 'webform']],
],
];
I expect the "webform" element (which is based on an entity reference field to select a webform) to be visibly marked as required when "Webform" is chosen in the "type" form element. The visibility state works as expected, the required state not. Even the workaround from Conditional Form Fields – The State 'required' → doesn't work:
$form['webform']['widget'][0]['target_id']['#states'] = [
'required' => [':input[name="type"]' => ['value' => 'webform']],
];
1. Create a content type with a "String list" field and an entity reference field for the target type "webform" (other target types might work as well) producing an edit form with structure as above
2. Create a new entity of that content type.
Problems:
1. Mandatory asterisk is not shown for webform entity reference selection field when the Webform option is selected
Active
11.0 🔥
forms system