We have been using Field States UI module with some success, but the Comparison Value does always not work for multiple values, I have tried to modify the valuse right in the entity_form_display.node yml file but no luck. I will also try the Conditional Fields module for D8. I also want to try to do this using code. I am trying an example using hook form alter taken from this post. But I cant get it to work. https://stackoverflow.com/questions/35380720/drupal-8-conditional-field. Should I be using drupal_process_states instead? Here is my code, I have two term reference fields field_test2 and field_test3. If you select the term id 15 from field_test2 then field_test3 will become visible.
use Drupal\Core\Form\FormStateInterface;
function mymodule_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'node_page_form' || $form_id == 'node_page_edit_form') {
return;
}
if (isset($form['field_test2'])) {
$states_when_category_is_design = array(
'visible' => array(
':input[name="field_test2"]' => array('value' => '15'),
),
);
if (isset($form['field_test3'])) {
$form['field_test3']['#states'] = $states_when_category_is_design;
};
}
}