I am using FAPI's AJAX property to save nodes asynchronously. When the associated AJAX callback gets called, it gets passed the $form and $form_state parameters respectively. I then simply call drupal_render($form)
from the AJAX callback and voilá, the node edit page is refreshed asynchronously. This works well.
The problem that I am having is that I am only replacing the form, but I also want to replace the page title. The page title is not part of the node edit form; so I could change the node title on the edit form, but the page title would remain stale when saving and refreshing the form (note: the edited title does get saved into the db). I cannot target an element sitting higher in the DOM hierarchy because (ie, by changing pointing the wrapper to the body) because the AJAX callback is only aware of the form's contents.
drupal_render($form)
works great, but I have the fear that if I where to point the wrapper to the body (or somewhere near it) and render the whole page, that this would have unintended consequences (such as skipping certain rendering steps, resulting in incomplete DOM data). That's why I thought of maybe adding a second AJAX callback to the form submit action: one for handling the form itself, another AJAX callback for handling the page title. Do you know if having more than one callback is possible? Can you think of a way of targeting two separate wrappers using FAPI's AJAX? Do you know if the path (instead of callback) property provides a solution for my problem? If path does work feel free to augment your answer with a short example.
Please limit answers to functionality supported by Drupal core. I am not interested in third-party modules that use their own javascript logic (ie, ctools, etc).
Sample code:
// Add ajaxified save button in hook_form_FORM_ID_alter (foo_form_node_form_alter).
$form['actions']['ajax_save']['#type'] = 'submit';
$form['actions']['ajax_save']['#access'] = TRUE;
$form['actions']['ajax_save']['#value'] = 'Save';
$form['actions']['ajax_save']['#submit'] = array(0 => 'foo_node_form_submit');
$form['actions']['ajax_save']['#weight'] = 9;
$form['actions']['ajax_save']['#ajax'] = array(
'wrapper' => $form['#node']->type. '-node-form',
'callback' => 'foo_ajax_callback',
'method' => 'replace',
'effect' => 'fade',
);
...
function foo_ajax_callback(&$form, &$form_state = null) {
$commands = array('#type' => 'ajax', '#error' => FALSE, '#commands' => array());
$output = drupal_render($form);
$commands['#commands'][] = ajax_command_insert(NULL, $output);
// Prepend status messages to the node form.
$commands['#commands'][] = ajax_command_prepend(NULL, theme('status_messages'));
// Update the title on the page.
$commands['#commands'][] = ajax_command_insert(NULL, $output);
return $commands;
}