Ajax callback on Views exposed form filter

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

Ajax submission leads to => An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports

Any working example would be great! Thanks.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Ajax callback on Views exposed form filter

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.