The specified #ajax callback is empty or not callable when #tree is TRUE

Created on 3 April 2017, almost 8 years ago
Updated 19 September 2023, over 1 year ago

When select is changed drupal generate error - Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of E:\xampp\htdocs\m827\core\lib\Drupal\Core\Form\FormAjaxResponseBuilder.php).

When #tree is false its work perfectly, and when I turned on #tree to TRUE, it gives error of empty callback, I have checked the in FormAjaxResponseBuilder.php found out when change in select element, in triggringElement it returns the submit(filter_search) element.

One more thing when I used uniqid() in $rowId, it gives empty callback error, but if I provide hardcoded value in the $rowId, it worked perfectly.

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['tool-container'] = array(
	'#type' => 'container',
	'#prefix' => '<div id="tool-container-main">',
	'#suffix' => '</div>',
	'#tree' => TRUE,
  );
  
  $rowId = uniqid();
  //$rowId = 'fghfg567df';
  
  $form['tool-container'][$rowId] = [
	'#type' => 'container',
  ];
  
  $form['tool-container'][$rowId]['tools'] = [
	'#type' => 'select',
	'#title' => t('Tools selected'),
	'#empty_option' => '-Select-',
	'#options' => [1=>1,2=>2,3=>3],
	'#required' => TRUE,
	'#ajax' => [
	  'callback' => '::updateTframeCostPrice',
	  'wrapper' => 'tool-container-main',
	  'effect' => 'fade',
	  'event' => 'change',
	  'progress' => array('type'=> 'throbber', 'message'=> NULL),
	],
  ];
  
  $form['filters-submit'] = [
	'#type' => 'submit',
	'#name' => 'filter_search',
	'#value' => $this->t('Search'),
	'#limit_validation_errors' => array(),
  ];
  return $form;
}
🐛 Bug report
Status

Closed: cannot reproduce

Version

9.5

Component
Ajax 

Last updated 1 day ago

Created by

🇮🇳India mayank.diceinfocom

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • Status changed to Closed: cannot reproduce over 1 year ago
  • 🇳🇿New Zealand quietone

    Since we need steps to reproduce to continue here and they haven't been supplied since asking 8 months ago, I am closing this.

    Therefore, closing as cannot reproduce. If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

    Thanks!

Production build 0.71.5 2024