I am using Webforms in Drupal 8, and I have a checkbox on a webform composite element which basically show/hides an address field.
public static function getCompositeElements() {
$elements = [];
$elements['address_same'] = [
'#type' => 'checkbox',
'#title' => t('They live at the same address'),
];
$elements['address_postal'] = [
'#type' => 'textfield',
'#title' => t('Street address'),
'#states' => [
'visible' => [
':input[name="spouse[address_same]"]' => array('checked' => FALSE),
]
]
];
}
The issue I have is that this group of fields may have one or more values on the form, and if there is more than one then the states get all confused because they are targeting the wrong field.
This may be the same on Drupal 7, but I can not figure out how to give #states a generic selector for address_same so that it only targets the one just before it.
Most likely I will just go write some custom jQuery for this, just thought there must be a way of doing it.