How to pre-populate the dropbox

Last modified: July 27, 2009 - 22:39

In some cases, you'll want to pre-populate the dropbox. The answer is very simple. Use #default_value.

Example

Here's an example for a taxonomy Hierarchical Select.

The vocabulary with vid 3 has the following terms:
- 6: Ford
- 7: Fiesta

The following piece of code:

<?php
$form
['taxonomy'][$vid] = array(
   
'#type' => 'select',
   
'#title' => t('My taxonomy select'),
   
'#config' => array(
     
'module' => 'hs_taxonomy',
     
'params' => array(
       
'vid' => 3,
      ),
     
'save_lineage'    => 1,
     
'enforce_deepest' => 0,
     
'resizable'       => 0,
     
'level_labels' => array(
       
'status' => 0,
      ),
     
'dropbox' => array(
       
'status'   => 1,
       
'title'    => t('Cars'),
      ),
     
'editability' => array(
       
'status' => 0,
      ),
    ),
   
'#default_value' => array(6, 7),
  );
?>

would result in:

AttachmentSize
HS_pre-populated_dropbox.png6.86 KB
 
 

Drupal is a registered trademark of Dries Buytaert.