Skip to main content
edited tags
Link
Source Link

ahah and fieldset 'collapsed' state

On my drupal 6 site I have the following fieldset in one of my forms ($cur_div_wrapper_name is a variable I have set to be "share_opp_with_rep_div"):

$form['add_rep_share_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Share with Rep'),
    '#prefix' => '<div id="' . $cur_div_wrapper_name . '">',
    '#suffix' => '</div>',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
);

As you can see, the fieldset is collapsible and has a state of collapsed by default.

Inside of this fieldset I have two selects. One of these selects ("share_with_rep") changes it's values when the other select ("share_with_rep_region") is changed. I utilize ahah and the ahah_helper module to make this work.

$form['add_rep_share_fieldset']['share_with_rep_region'] = array(
    '#type' => 'select',
    '#title' => t('Region'),
    '#options' => $regions_lov,
    '#default_value' => $default_share_opp_region,
    '#ahah' => array(
        'event' => 'change',
        'path' => ahah_helper_path(array('add_rep_share_fieldset')),
        'wrapper' => $cur_div_wrapper_name,
    ),
);

$regions_lov is a variable containing an array of options for this select.

$form['add_rep_share_fieldset']['share_with_rep'] = array(
    '#type' => 'select',
    '#title' => t('Sales Rep'),
    '#options' => $rep_user_lov,
    '#default_value' => $default_share_opp_rep,
);

$rep_user_lov is a variable containing an array of options for this select.

The user has to un-collapse the fieldset in order to see the two selects. When I change the "share_with_rep_region" select the other select ("share_with_rep") changes automatically. This works fine.

My problem is that the fieldset does not keep it's un-collapsed state after changing the "share_with_rep_region" select, and the user has to click on the fieldset again to un-collapse it and choose a value for "share_with_rep".

Does anyone know if it's possible to pull the collapsed state of the fieldset and remember it so the user does not have to click it again to view the contents after changing the "share_with_rep_region" select?

Thank you!