If we select a value in a drop-down list field(A), then we need to display and set as required field(B).
Note: the field(B) is a date range.
I tried to add states with a hook form alter
$form['field_b']['#states'] = [ 'visible' => [ ':input[name="field_a"]' => ['!value' => '_none'] ], 'required' => [ ':input[name="field_a"]' => ['!value' => '_none'], ], ];
As you see I use: '!value' to negate a value and '_none' for no value. So, It will not be required if there is no value selected
This code didn't work. It display the field B, but it is not mandatory.
We found that there is an issue with core https://www.drupal.org/project/drupal/issues/2855139
At the end issue was closed, but it didn't work for us. It worked with texte fields but not for our rage date.