Form API documentation for #ajax['callback'] is incomplete

Created on 21 September 2012, over 12 years ago
Updated 26 March 2025, 14 days ago

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.

🐛 Bug report
Status

Closed: won't fix

Component

API documentation files

Created by

🇳🇱Netherlands a.ross

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024