"Apply" exposed filters button starts export instead of filtering

Created on 14 February 2023, almost 2 years ago
Updated 13 August 2024, 3 months ago

Problem/Motivation

When using a data export attached to a view with exposed filters, clicking the "Apply" button to filter the view will instead export the view as if I'd clicked the data export button.

Steps to reproduce

  1. Import the provided view configuration, which has both a default display and a data export.
  2. Create a node with a view field.
  3. Embed the view and select the default display.
  4. Give the node a URL alias of /test
  5. Save the node.
  6. View the node, and click the Apply button on the view filters
  7. The data is exported to CSV file instead of filtering the view.

Viewing the page HTML confirms that the Apply button's surrounding <form> attribute is going to the export path.

It should be noted that this affects any form buttons, including the Reset button, because the form's action URL is wrong.

Workaround

use Drupal\Core\Url;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_views_exposed_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
  $path = Url::fromRoute('<current>')->toString();
  $form['#action'] = $path;
}

This workaround won't work if "Use AJAX" is enabled for the view display. See comment #17 πŸ› "Apply" exposed filters button starts export instead of filtering Active for a more thorough workaround.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024