I’m trying to add an #ajax callback method to my views exposed form filter select box. But it seems the form have some issues with the callback. My code is pretty simple
/** * Implements hook_form_FORM_ID_alter() for views_exposed_form. */ function mymodule_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) { if ($form['#id'] == 'views-exposed-form-viewid') { $op = ['hi' => 'hi', 'all' => 'all']; $form['test'] = [ '#type' => 'select', '#name' => 'test', '#empty_option' => 'none', '#options' => $op, '#ajax' => [ 'callback' => '_my_call', 'event' => 'change', 'wrapper' => 'edit-output-test', 'progress' => [ 'type' => 'throbber', ], ], ]; $form['callfield'] = [ '#type' => 'select', '#options' => [], '#prefix' => '<div id="edit-output-test">', '#suffix' => '</div>', ]; } } function _my_call(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); $message = 'test'; $response->addCommand(new HtmlCommand('#edit-output-test', $message)); return $response; }
When I try to change the ‘test’ select box from view edit screen I get the below error
"SymfonyComponentHttpKernelExceptionHttpException: The specified #ajax callback is empty or not callable. in DrupalCoreFormFormAjaxResponseBuilder->buildResponse() (line 67 of /var/www/mypoc/docroot/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php)."
When I change the filter from the front end I get the following error
"An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (32 MB) that this server supports."
And I see a lot of similar issues –
Ajax callback is not working on views exposed filters
Any working example would be great! Thanks.