0

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!

1

I'd do something along the lines of checking the value of share_with_rep_region before defining the collapsed state of your fieldset. i.e.:

// whatever the default value of the select is before 
// the user has interacted with it in any way
$default_value = '';

// set collapse true
$collapse = TRUE;

// assuming you're passing $form_state into your form definition, if not, do so
if ($form_state['storage']['add_rep_share_fieldset']['share_with_rep_region'] !== $default_value) {
    $collapse = FALSE;
}

$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' => $collapse,
);

I hope this shows the basic idea behind what I'm trying to say: $collapse = true by default, IF the user has interacted with the form in any way, $collapse = false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.