Skip to content

Instantly share code, notes, and snippets.

@wimleers
Created January 4, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wimleers/4f219d2b878ad673fe40 to your computer and use it in GitHub Desktop.
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.
'#process' => array('ctools_dependent_process'),
'#dependency' => array('radio:' . CDN_STATUS_VARIABLE => array(CDN_TESTING, CDN_ENABLED)),
// See the ugly typecasting hack to enforce correct behavior!
'#states' => array(
'invisible' => array(
':input[name="' . CDN_STATUS_VARIABLE . '"]' => array('value' => '' . CDN_DISABLED),
),
),
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