I'm trying to use the states API in Drupal 8 but I'm having trouble, and I'm also having difficult debugging.
Use case:
On user accounts, I have a taxonomy term reference field called Gender. The three terms in the taxonomy vocabulary are female, male, and other.
I also have a text field on user accounts called Other. I want to show this Other field if and only if Gender is set to other (term ID: 27).
Here is the code I'm using:
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$form['field_gender_other']['#states'] = array('visible' =>
array('input[name="field-gender"]' => array('value' => '27'),
),
);
}
I based this off of code I used for Drupal 7. Unfortunately, it's not doing anything.
I looked at StateDemo.php
in the fapi submodule of the Examples module for Drupal 8, but that's for building a new form, and I'm trying to modify an existing form.