Reset button is not displaying in Exposed filter block when using Ajax

Created on 27 October 2021, about 3 years ago
Updated 18 January 2023, about 2 years ago

Problem/Motivation

Drupal 9.2.7. All modules have latest versions.
The reset button is not even loaded to DOM, when using exposed filters form in a block with Ajax enabled.
There are no errors in the console.

Related issue - https://www.drupal.org/project/better_exposed_filters/issues/3232707 šŸ› Reset button does not display when using AJAX Fixed
But it was addressed to Better Exposed Filter module, which I'm not using.
So my guess is that it's a core bug.

Steps to reproduce

Modules, that use Views:

  1. Views
  2. Views UI
  3. Chaos Tools Views
  4. Metatag: Views
  5. Simple XML Sitemap (Views)
  6. Slick Views
  7. Views Contextual Filter Default Entity Field Values

The last two were installed after I found this bug.

Steps:

  1. Create View
  2. Add filters and expose them
  3. Exposed form in block: Yes
  4. Exposed form style: Basic
  5. In form settings " Include reset button" is checked
  6. Use AJAX: Yes
  7. Place the filtrers block on a view page
  8. Go to your view page, make changes to form, view changes, Reset button doesn't show up.
  9. But if you go to /view-page?field_name_value=something - Reset button is displayed.

If "Exposed form in block" is NO, then the Reset button is there, as expected. When I click on it it doesn't use ajax and redirects to /view-page/All, but there is another issue for that already.

Proposed resolution

Make it work )))

šŸ› Bug report
Status

Needs review

Version

9.5

Component
ViewsĀ  ā†’

Last updated 2 days ago

Created by

šŸ‡·šŸ‡ŗRussia bigboy

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work almost 2 years ago
  • šŸ‡ŗšŸ‡øUnited States smustgrave

    Can confirm the issue in D10

    Moving to NW as there was no patch.

    Issue summary will have to be updated with before/after screenshots with fix. Also proposed solution (when one is figured out)

  • šŸ‡ŗšŸ‡øUnited States socalerich

    I am experiencing the same thing. As a side note, I am using the Views AJAX History module which, even when using AJAX, it will add the search criteria query params to the browser URL so you can preserve deep linking. When this is added and you do your initial search by, in my case, choosing a checkbox that filters the results, I initially do not see the reset button, but if I immediately refresh the page with the query parameters in the URL, the reset button appears. So this is almost certainly an AJAX issue.

  • šŸ‡ŗšŸ‡øUnited States socalerich

    I'm not sure if this will help anyone else, but I have come up with a temporary work around for this. It's a little hackey, but it is working for me. The prerequisite though is that you have the Better Exposed Filters module and the Views AJAX History module installed and have your view setup to use AJAX History, which can be enabled in the AJAX settings of your view. This will essentially add URL parameters to the URL with your filters even though you are using AJAX. This is actually a plus as far as I am concerned, because it enables bookmarking of filters that were applied to your search. Other than that, just set your Reset button to "Always display" in the BEF settings. Then use this JavaScript:

    /*
    There is currently a bug where if AJAX is enabled for a view and you configure a Reset button to show for exposed filters, the button will not appear when filters are selected. A temp work around is to configure the Reset button to always appear and then this script will initially hide the button, but then show it if there are any query parameters ie: filters have been applied.
    */
    
    (function ($, Drupal) {
      Drupal.behaviors.resetFilters = {
        attach: function (context, settings) {
          $(".form-submit[id^=edit-reset]").hide();
          if (window.location.search) {
            $(".form-submit[id^=edit-reset]").show();
          }
        },
      };
    })(jQuery, Drupal);
    
  • šŸ‡ŗšŸ‡¦Ukraine TŠ°o

    quick solution with hook_form_alter()

        $form['buttons'] = $form['actions'];
        unset($form['actions']);
    

    But it really needs to be fixed.

  • šŸ‡ŗšŸ‡øUnited States jayhuskins

    I think I found where the behavior is coming from:
    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...

    Here the reset button is explicitly ignored from the ajax form because "Many things break during the form reset phase if using AJAX". There are two options for moving forward on this issue

    1. Keep the reset button in the form, but do not use it with AJAX.
    2. Keep the reset button in the AJAX form and fix the "Many things" that will subsequently break
  • Added IS template and updated minor changes.

  • šŸ‡®šŸ‡³India adwivedi008

    Is there any update on this issue? This is an issue if we are using Ajax and a better-exposed filter together

    Any workaround would also be appreciated

  • šŸ‡ŗšŸ‡øUnited States sea2709 Texas

    I found a workaround solution based on this article https://www.drupal.org/forum/support/post-installation/2018-02-28/how-to... ā†’

    Whenever a user clicks on the reset button in an ajax view, I trigger the event RefreshView on that view.

  • šŸ‡·šŸ‡“Romania dorutirlea

    The patch applied for field updates issue on exposed form in block, that you can find here https://www.drupal.org/project/drupal/issues/3032353#comment-15746970 āœØ Exposed forms in a block are not currently updated when Ajax filtering is executed Needs work , will fix the show/hide reset button problem as well.

  • šŸ‡·šŸ‡“Romania dorutirlea

    The patch applied for field updates issue on exposed form in block, that you can find here https://www.drupal.org/project/drupal/issues/3032353#comment-15746970 āœØ Exposed forms in a block are not currently updated when Ajax filtering is executed Needs work , will fix the show/hide reset button problem as well.

    Enjoy

Production build 0.71.5 2024