I am using Drupal 6.4. Not sure if same issue applies to Drupal 7.x

When I add the following checkbox ahah element, it works fine if I add it in the form initially.

If I add the element to the form as part of an ahah callback, the checkbox is added but the ahah event does not occur. I have applied the patch defined here:

http://drupal.org/node/299742

but it does not seem to fix the problem. Does this sound like a bug in ahah 6.x core?

    $form['test']['check'] = array (
    '#prefix' => '<p>',
    '#type' => 'checkbox',
    '#name' => 'Display_Debugging',
    '#title' => 'Display Debug Fields',
    '#default_value' => FALSE,
    '#ahah' => array(
        'path' => TEST_PATH,
        'event' => 'click',
        'wrapper' => TEST_WRAPPER,
        'progress' => array('type' => 'bar', 'message' => t('Grinding...')),
      ),    
   );

Comments

matths’s picture

I've got the same problem with Drupal 6.16.

If I add a checkbox manually and "statically" with

  $form['vocabularies_references']['testbox'] = array(
        '#title' => t('Testbox'),
        '#type' => 'checkbox',
				'#ahah' => array(
          'path' => 'analysis/ahah_callback',
          'wrapper' => 'analysis_vocabularies_references',
          'effect' => 'fade',
          'method' => 'replace',
        )
      );

AHAH handlers are added to the checkbox. But if this checkbox itself is only shown because of another AHAH action or rather because of $form_state['values'], AHAH handlers aren't added to this checkbox altough the code is nearly the same as the one above. (Only called $form['vocabularies_references']['lalala']['testbox'] instead of $form['vocabularies_references']['testbox']...)

Anyone got an idea how to solve this issue?

Regards,
Matt

matths’s picture

Following code snippet within the AHAH-callback function solved the problem:

// AHAH is not being nice to us and doesn't know about the "Remove" button.
  // This causes it not to attach AHAH behaviours to it after modifying the form.
  // So we need to tell it first.
  $javascript = drupal_add_js(NULL, NULL);
  if (isset($javascript['setting'])) {
    $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>';
  }
  

Taken from http://civicactions.com/blog/2009/jun/20/ajax_ifying_drupal_node_forms