Since there's no "#options" or #default_value field in the hierarchical select, how would I pre-populate the dropbox with items that a user would have selected in e.g. a previous form submit. I.e. the user selects one or more items within a HS form, submits the form and the selection gets stored in my module's database tables. At a later point the user wants to review and change his/her selection, once again presented in the HS form; in that case I need to pre-populate the HS dropbox with the entries as stored in the database.
How do I setup the form such that I can pre-populate the dropbox (I can't seem to find the specific info in neither the API doc nor the code samples)? Do I use hook_hierarchical_select_create_item() for this? Or do I use one (which one?) of the Javascript events for this; which of the JS events triggers before the HS is rendered first time before any user triggered events?

RK

CommentFileSizeAuthor
#1 Picture 1.png6.86 KBwim leers

Comments

wim leers’s picture

Assigned: Unassigned » wim leers
Priority: Critical » Normal
Status: Active » Fixed
StatusFileSize
new6.86 KB

Just set #default_value.

An example for a taxonomy HS.

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

The following piece of code:

$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 the attached screenshot.

rkoeten’s picture

It's working for me right now. Thanks for the clarification.

RK

wim leers’s picture

Title: pre-populate the dropbox » Documentation: how to pre-populate the dropbox
Component: Code » Documentation
Status: Fixed » Active

Great! :)

Actually, I should document this!

wim leers’s picture

Project: Hierarchical Select » HeyWatch CCK Field
Version: 5.x-3.0-rc3 »
Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.