I have a field on a custom content type which is a reference to a paragraph type, using the Paragraph (EXPERIMENTAL) widget. I'm trying to modify that widget to show and hide a field based on another field on the paragraph. Here is my widget alter code:
$field = 'field_supporter_form_fields';
$id_field = 'field_primary_custom';
$delta = $element['#delta'];
$id = sprintf('select[name="%s[%d][subform][%s]"]', $field, $delta, $id_field);
$element['subform']['field_field_type']['widget']['#states'] = [
'visible' => [
$id => ['value' => 'custom'],
],
];
$element['subform']['field_field_type']['widget']['#title'] = 'Blah!';
I know that I'm targeting the correct widget because I see the field title change to "Blah!", but the visibility of the field doesn't change.
Here's what the relevant part of the $element array looks like after the alter:
[#parents] => Array
(
[0] => field_supporter_form_fields
[1] => 0
[2] => subform
[3] => field_field_type
)
[#states] => Array
(
[visible] => Array
(
[select[name="field_supporter_form_fields[0][subform][field_primary_custom]"]] => Array
(
[value] => custom
)
)
)
The dependant field field_primary_custom
is a pair of radio buttons with values of either primary or custom. The name of the element on the page is field_supporter_form_fields[0][subform][field_primary_custom]
which matches what I have in my identifier.
Why isn't the visibility changing?