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

a.ross’s picture

Issue summary: View changes

Add link

a.ross’s picture

Issue summary: View changes

Add link to source code of relevant core function.

a.ross’s picture

Perhaps 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.

LeeHunter’s picture

Component: Correction/Clarification » API documentation files
LeeHunter’s picture

Issue summary: View changes

Slight clarification.

GersonJL’s picture

Issue summary: View changes
Issue tags: +FAPI reference