0

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

"Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->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.

0

Sounds like there is an ongoing core issue queue - https://www.drupal.org/project/drupal/issues/2842525

After applying the patch - https://www.drupal.org/files/issues/2020-03-27/2842525-83.patch this seems to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.