-
-
Save wimleers/4f219d2b878ad673fe40 to your computer and use it in GitHub Desktop.
#states does not support integer values, nor OR operator. I only got this to work because this is still a fairly simple use case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'#process' => array('ctools_dependent_process'), | |
'#dependency' => array('radio:' . CDN_STATUS_VARIABLE => array(CDN_TESTING, CDN_ENABLED)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See the ugly typecasting hack to enforce correct behavior! | |
'#states' => array( | |
'invisible' => array( | |
':input[name="' . CDN_STATUS_VARIABLE . '"]' => array('value' => '' . CDN_DISABLED), | |
), | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('CDN_DISABLED', 0); | |
define('CDN_TESTING', 1); | |
define('CDN_ENABLED', 2); | |
define('CDN_STATUS_VARIABLE', 'cdn_status'); | |
define('CDN_STATS_VARIABLE', 'cdn_stats'); | |
function some_form_function($form, &$form_state) { | |
// | |
// Only needed in Drupal 6, hurray for #states in Drupal 7! | |
ctools_include('dependent'); | |
$form[CDN_STATUS_VARIABLE] = array( | |
'#type' => 'radios', | |
'#title' => t('Status'), | |
'#required' => TRUE, | |
'#options' => array( | |
CDN_DISABLED => t('Disabled'), | |
CDN_TESTING => t('Testing mode'), | |
CDN_ENABLED => t('Enabled'), | |
), | |
'#default_value' => variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED), | |
); | |
$form[CDN_STATS_VARIABLE] = array( | |
'#type' => 'checkbox', | |
'#title' => t('Display statistics'), | |
'#return_value' => CDN_ENABLED, | |
'#default_value' => variable_get(CDN_STATS_VARIABLE, CDN_DISABLED), | |
// | |
// Here either #process and #dependency (D6) or #states (D7). | |
// | |
); | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment