According to the documentation of #ajax['callback'], the callback function defined by this property "can return HTML, a renderable array, or an array of AJAX Commands."
This issue is about that last statement, that the callback function can return an array of AJAX commands. This would mean the following:
return array(
ajax_command_replace($selector1, $html1),
ajax_command_html($selector2, $html2),
);
This, in fact, doesn't work, and no error message is produced. After hours of debugging and reading documentation, I found the solution in the source code of ajax_prepare_response(). The code of the callback function should do this:
return array(
'#type' => 'ajax',
'#commands' => array(
ajax_command_replace($selector1, $html1),
ajax_command_html($selector2, $html2),
),
);
How can we reflect this in the documentation? I'm not sure if it is appropriate to put this information in that same paragraph.
Comments
Comment #0.0
a.ross commentedAdd link
Comment #0.1
a.ross commentedAdd link to source code of relevant core function.
Comment #1
a.ross commentedPerhaps the structure should be defined in the doc of the function, and then the Form API docs should link to ajax_prepare_response? In that case we also need a core issue.
Comment #2
leehunter commentedComment #2.0
leehunter commentedSlight clarification.
Comment #3
gersonjlComment #4
quietone commentedThis is for the Drupal 7 Form API reference. Since Drupal 7 is past end-of-life this is now a "won't fix".
Work on documentation for form elements for supported versions of Drupal is at #2486967: [meta] Move/Create Form Element Documentation and #3313535: [Meta] Improve documentation for Render and Form Elements.