I tried to add a checkboxes widget by ahah. The submission is by click a button with #ahah property, and if I insert a textfield or select, it works as expected, but if I try to insert a checkboxes widget, it only shows the rendered checkboxes form-item, not any of the options.

Is it a bug?

Comments

robinmofo’s picture

I am having this trouble also, it works fine if I add just a text field both the label and textfield show... it's jsut for checkboxes the label appears but no checkboxes are present. I'm using the official AHAH guide from http://drupal.org/node/331941.

Would be nice to get someone's comment on this as I'm sure more people will want to know (and this is one of the search results from this forum) - I read another post /patch about not being able to put AHAH events to checkboxes, so I updated to 6.10 just in case but I'm still getting the same issue.

Any help please? (I've learnt so much myself about Drupal but I'm inclined to think this is a bug / expected functionality - if needs be I'll be adding my own checkboxes patch for this - but would like to get someone else's comments first)

robinmofo’s picture

Hi,

I was just about to raise a new issue. so I'll quickly update this post.

I got around the "checkboxes" issue by creating a function that returned an array of "checkbox" type (not checkboxES) and it works perfectly (in fact it was a good way to split my shown and hidden checkboxes fieldsets which are based on admin settings for the module)

sam.clayton@gmail.com’s picture

Version: 6.6 » 6.12

I'm seeing this same issue on 6.12. Label and description are shown, but no actual checkboxes. Returning text-field form elements from the same callback works fine.

Is this an issue with drupal_render?

function example_ahah_callback() {
  $form_state = array('storage' => NULL, 'submitted' => FALSE, 'rebuild' => TRUE);
  $form_build_id = $_POST['form_build_id'];
  
  $form = form_get_cache($form_build_id, $form_state);
  
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;
  
  drupal_process_form($form_id, $form, $form_state);

  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  $options = array(
    'Micro'   => t('Micro'), 
    'Small'   => t('Small'), 
    'Medium'  => t('Medium')
  );

  $form['image_size'] = array(
    '#type'          => 'checkboxes',
    '#title'         => t('Thumbnail size'),
    '#default_value' => variable_get('example_image_size', 'Small'),
    '#options'       => $options,
    '#description'   => t('Select the size of the image to include.'),
    '#tree'          => TRUE
  );

  $size_choice_form = $form['image_size'];
  $output = theme('status_messages') . drupal_render($size_choice_form);
  
  drupal_json(array('status' => TRUE, 'data' => $output));

}
cntlscrut’s picture

I, too have been having the same issue. In my tests I have found that the only FAPI types that do not render properly are "radios" and "checkboxes".

I read above about creating am array of checkbox types, but for my current project that is not a feasable solution.

maxB’s picture

I'm having the same problem with inserting a checkboxes form-element with a ahah-callback.

I thought about the mentioned array solution before. But I just wanted to search for a perfect solution. Actually there's no bug fix available for this - and I'm just not that into the whole AHAH topic so that I could search for the bug and fix it. Therefore I'm waiting for a clever person that knows how to handle that one!

darrick’s picture

I called the form_builder function before rendering the checkboxes:

http://api.drupal.org/api/drupal/includes--form.inc/function/form_builder/6

function merci_staff_update_groups() {
  $form_state = array('storage' => NULL, 'submitted' => FALSE);
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;

  global $user;
  $current_user = $user;
  $user = user_load(array('name' => $form['#post']['name']));
  og_form_add_og_audience($form,$form_state);
  $user = $current_user;

  $form = form_builder($form_id, $form, &$form_state) ;

  // This section prepares the actual output that will be returned to the
  // browser.
  $selected_portion = $form['og_nodeapi']['visible']['og_groups'];
  
  // To avoid doubling-up the wrapper, we have to remove it here.
  unset($selected_portion['#prefix'], $selected_portion['#suffix']);

  $output = drupal_render($selected_portion);

 // Output the results and exit.
  print drupal_json(array('status' => TRUE, 'data' => $output));
  exit();
}

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.