Problem/Motivation

Views exposed filters reset button does not work if the previous values match with the form values.

Steps to reproduce

Enabled modules

  • Better Exposed filters
  • Views data export

Create a view page/block with

  • Basic config to show content, some exposed filters etc.
  • Exposed form in block = yes
  • Exposed form style = better exposed filters
    • "Include reset button (resets all applied exposed filters)" enabled
    • "Always show reset button" disabled
  • "Use ajax" = yes

Also create data export that is attached the list

  • Path settings
    • Redirect back to the page/block you created
    • "Include query string parameters on redirect" enabled
  • Attach to your page/block
  1. Filter the list using exposed filters
  2. Export the filtered data
  3. Get redirected back to the list, reset button is visible
  4. Click reset button => nothing happens

This seems to be because of core/misc/form.js has

if (previousValues === formValues) {
  e.preventDefault();
} else {
  $form.attr('data-drupal-form-submit-last', formValues);
}

that disables the reset button.

Proposed resolution

The reset button would always reset the filters by reloading the page. The form.js onFormSubmit should detect if reset button is pressed and not prevent submission.

Reading the activeElement data-drupal-selector value one could detect if reset was pressed but that might not work in all browsers. Anyways possible fix could be

if (previousValues === formValues && $(document.activeElement).data('drupal-selector') !== 'edit-reset') {
  e.preventDefault();
} else {
  $form.attr('data-drupal-form-submit-last', formValues);
}

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

-

Issue fork drupal-3335209

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

MikaT created an issue. See original summary.

mikat’s picture

StatusFileSize
new983 bytes
cilefen’s picture

Version: 9.4.x-dev » 9.5.x-dev
Status: Active » Needs review
Issue tags: -views exposed filters, -Reset Button

I am moving this to the bug fix branch and setting it for review.

_utsavsharma’s picture

StatusFileSize
new1.21 KB
new1.21 KB

Tried to fix CCF for #2.

mikat’s picture

StatusFileSize
new1.56 KB
new1.56 KB

9.4 patch with updated form.es6.js

mikat’s picture

mikat’s picture

Version: 9.5.x-dev » 9.4.x-dev

Changes version to 9.4.x.

_utsavsharma’s picture

StatusFileSize
new1.74 KB
new1.17 KB

Fixed CCF for #5.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new143 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

_utsavsharma’s picture

StatusFileSize
new633 bytes
new633 bytes

patch for 10.1.x.

cilefen’s picture

Version: 9.4.x-dev » 9.5.x-dev
Issue tags: +JavaScript

Let's put this back on the bug fix branch. Drupal 9.4 does not get bug fix releases any more (only security). Patches for 9.4.x will not be committed.

kemsnake’s picture

Issue tags: -JavaScript +JavaScript
StatusFileSize
new1.21 KB

Uploaded patch for 9.5.x

suresh prabhu parkala’s picture

StatusFileSize
new1.63 KB

Re-rolled patch against latest 9.5.x. Please review.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.