When I have a radio form item where it isn't applicable to define a default_value then all form items that depend on the radio are shown regardless of their dependency values. Upon selecting an option in the radio the dependency works like expected (items with different dependency values are hidden).

In case I haven't used dependent correctly - here are the form items:

$form['source'] = array(
  '#type' => 'radios',
  '#title' => t('Choose the object'),
  // Often $form_state['taglist']->source['source'] is not set so default_value is not present.
  '#default_value' => $form_state['taglist']->source['source'] ? $form_state['taglist']->source['source'] : NULL,
  '#options' => $options['source'],
);

foreach ($options['source'] as $viewname) {
  $form[$viewname] = array(
    '#type' => 'select',
    '#title' => t('Displays for view !viewname', array('!viewname' => $viewname)),
    '#default_value' => $form_state['taglist']->source['display'] ? $form_state['taglist']->source['display'] : 'default',
    '#options' => $options['display'][$viewname],
    // Works when an option is selected in the radio form 'source'.
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:source' => array($viewname)),
  );
}

Comments

Roi Danton’s picture

Category: support » bug
Status: Active » Needs review
StatusFileSize
new790 bytes

Problem was related to ctools. I've written a patch to fix it. Works in my case (also tested with other dependencies using checkboxes). Patch is against Head.

Benwick’s picture

Thanx Roi it's cool 15 characters patch, works fine for me.

I found and "anomaly" about #654218: Dependent: Form's fieldset don't hide, however radios and checkboxes don't shown

Please take a look at it!

Roi Danton’s picture

Status: Needs review » Reviewed & tested by the community

Since the patch works for Benwick and I haven't encountered any problems with it yet either (using it for Linodef) I change issue status.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Looks good to me. Thanks for finding and fixing this one. I wasn't looking forward to having to hunt this one down.

Status: Fixed » Closed (fixed)

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

eojthebrave’s picture

Version: 6.x-1.2 » 6.x-1.8
Status: Closed (fixed) » Needs review
StatusFileSize
new577 bytes

Looks like this got fixed in 7.x but not 6.x.

mimrock’s picture

StatusFileSize
new490 bytes

Actually, this patch is not fixing the real issue. It may work as a hack, but the real source of the bug is the wrong implementation of inArray function in dependent.js

I submit a patch for the 6x-1.8 version, feel free to use it.

Status: Needs review » Needs work

The last submitted patch, 630982-6-form-items-dont-hide.patch, failed testing.

mimrock’s picture

Status: Needs work » Closed (fixed)

This issue has been already fixed in an other thread and the patch has been committed. I'm not a maintainer of ctools but I think we can close this issue.

http://drupal.org/node/941584