drupal_render in hook_form_alter prevents javascript from being included in the header I'm calling drupal_render to render a textarea element in another element's #prefix field in hook_form_customtype_node_form_alter().  When I load the form, most of the script tags in the header do not get printed.  If I comment out the line with drupal_render they print out and the accordions and sliders load on the page.  

Why would calling drupal_render prevent some of the javascript files from being included in the page header?

UPDATE

Here's my code:

$deltas = preg_grep('/^[0-9]*$/',     array_keys($form['field_recommendation_reference'][LANGUAGE_NONE]));
foreach ($deltas as $delta) {
  if ($form['field_recommendation_reference'][LANGUAGE_NONE][$delta]['field_key']['#default_value']['finding_wrapper'] == $wrapper_field_name) {
    $wrapper = $form[$wrapper_field_name];
    $wrapper['#printed'] = FALSE;
    $wrapper['#value'] = 'test';
    //$form[$field]['#suffix'] = drupal_render($wrapper);
    dpm(drupal_render($wrapper));
  }
}


When I output the element with dpm, the form loads all of the javascript.  Also, when I include the markup without using drupal_render, the page loads correctly.

If I included the rendered markup manually the form doesn't load all of the javascript.  Could it be a conflict with id's being used already?  I have the same element stored in the $form array but with #printed set to TRUE.

Found the Issue

if I set #autocomplete_path = '', the form element's markup does not disrupt the rest of the page.  Is it possible to get autocomplete to work with drupal render?  I saw some comments related to this on the drupal_render api documentation
Setting the #id to $wrapper['#id'] = drupal_html_id('edit-' . str_replace('_', '-', $wrapper_field_name));  resolved the issue.  theme_textarea was unable to get a value for $element['#id'].

edit

I still had trouble getting the #ajax elements to be processed even after adding a call to ajax_pre_render_element.

I restructured my alter hook so that it prints the textarea inside the form element that I'm trying to append to. that way it prints both fields one after the other.  This way, I'm not touching drupal_render and everything works.