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 CreditAttribution: a.ross commentedAdd link
Comment #0.1
a.ross CreditAttribution: a.ross commentedAdd link to source code of relevant core function.
Comment #1
a.ross CreditAttribution: 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 CreditAttribution: LeeHunter commentedComment #2.0
LeeHunter CreditAttribution: LeeHunter commentedSlight clarification.
Comment #3
GersonJL