Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It appears that the table FAPI does not honor the #states parameter.
$form['notify'] = array(
'#type' => 'table',
'#header' => array(t('Role'), t('Count')),
'#attributes' => array(
'id' => 'fisma-user-settings-form',
),
'#caption' => t('Roles to Notify of Account Action'),
'#states' => array(
'invisible' => array(
':input[name="enable"]' => array('value' => '0'),
),
),
);
Whereas, if I duplicate the code on a fieldset, it works fine.
$form['emails'] = array(
'#type' => 'fieldset',
'#title' => t('Email subjects and bodies'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('The role(s) chosen above will be notified when a user account is created, updated, or deleted.')
. ' ' . t('The subject and body fields for each type of email are specified below.')
. ' ' . t('The following substitutions are available:')
. '<ul><li>' . t('@actor - the person who performed the action.')
. '</li><li>' . t('!user - the link to the user account.')
. '</li><li>' . t('@name - the name on the user account.')
. '</ul>',
'#states' => array(
'invisible' => array(
':input[name="enable"]' => array('value' => '0'),
),
),
);
Comments
Comment #2
Dave ReidNo, tables do not honor states. You'd need to wrap the table in a fieldset or a container element in order for this to work. This is by design and you'd need to file an issue in core to resolve this as this element is not provided by this module.
Comment #3
Dave ReidTo clarify, I don't believe the table element in Drupal 8 supports states. It would need to be fixed there first.