I have an AJAX form. I'm using drupal_add_js() after AJAX calls to update 'settings' and pass new information to my Drupal.behaviour object. However, the results are being merged instead of replaced. I know this is by design but it's messing up my Javascript code because I end up with information from the last callback. Does anyone know of a good workaround for this?
Update:
Current workaround is overriding the code so settings is replaced rather than merged, though only for the page my form is in.
Drupal.ajax.prototype.commands.settings = function (ajax, response, status) {
ajax.settings = response.settings;
};
Feels wrong, but things are working as expected.
Solution:
The final solution I used, as solved by Alice Heaton, isn't to override code in ajax.js, instead I returned both the form and an AJAX command in the forms AJAX callback:
function my_ajax_callback($form, $form_state) {
$commands = array();
$commands[] = ajax_command_settings(array(
'key1' => 'value1',
'key2' => 'value2',
));
$output = drupal_render($form['locator']);
$commands[] = ajax_command_insert(NULL, $output);
return array('#type' => 'ajax', '#commands' => $commands);
}