Reset button does not use AJAX

Created on 30 August 2018, about 6 years ago
Updated 20 August 2024, 3 months ago

In any View that uses Better Exposed Filters and has both a submit button and a reset button, only the reset button refuses to use AJAX. Instead, it brings you to a URL such as:

/views/ajax?state=166&[...]&op=Clear+all&items_per_page=10

All other elements of the BEF form work as expected. It is only the reset button that does not refresh the page via AJAX.

As it stands, I have to use Javascript to override the functionality of this button so that it unchecks all options on the form and forces a form submit (which itself uses AJAX).

๐Ÿ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States TerranRich

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada nikathone Ontario
    +++ b/src/Plugin/views/exposed_form/BetterExposedFilters.php
    @@ -838,10 +778,21 @@ class BetterExposedFilters extends InputRequired {
    +    if (isset($form['actions']['reset'])) {
    
    @@ -933,4 +856,229 @@ class BetterExposedFilters extends InputRequired {
    +            $handler->value = $handler->options['value'];
    

    Is there any particular reason this code $handler->value = $handler->options['value']; is implemented here? I can't seem to see the benefit of having it. I went ahead and commented it and the reset button still working fine.

    Asking because its presence is causing a php warning when a custom handler doesn't have a value option.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States alison

    I do think most of this is a core issue -- I can't speak to the auto-submit use cases -- but (*after* submitting a new issue, of course!) I see this existing issue:
    ๐Ÿ› Views exposed form action incorrect for embedded views' displays with other displays with paths Needs work

    And now my new issue, which maybe should be marked as a duplicate, but I'll share anyway, in case our different explanations are helpful to anyone:
    ๐Ÿ› On views with AJAX enabled, exposed filter "reset" causes page load Active

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine bvakulin

    @er.garg.karan Thanks for the patch #74.
    But Reset button still do not work for the next conditions:
    Exposed form in block: Yes.
    Use AJAX: Yes
    In this scenario when click reset button nothing happens.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cgrouge

    #74 patch is working for me with better exposed filters, auto-submit, ajax, and a modified input--submit.html.twig file.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States vlyalko

    I am not sure if this is a related issue. I am using views_filters_populate to combine multiple fields into one filter and ajax reset button does not clear the results when view is being filtered on this populate combined filter field.
    I have applied the https://www.drupal.org/project/better_exposed_filters/issues/2996297#com... ๐Ÿ› Reset button does not use AJAX Needs work patch and it does not fix the issue I am having.
    Testing in drupal 9 and drupal 10
    Will appreciate any guidance on fixing this issue.

  • In my case, patch #74 causes reset button to cleanup filters, but not reload results. Pressing reset button a second time alse results are AJAX reloaded.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany stborchert

    This error still exists in 6.0.x. The patches doesn't apply though.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany stborchert

    stBorchert โ†’ changed the visibility of the branch 6.0.x to hidden.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany stborchert

    stBorchert โ†’ changed the visibility of the branch 8.x-5.x to hidden.

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany stborchert

    Created a merge request based on the previous patches and that works for us.

  • Pipeline finished with Success
    6 months ago
    Total: 218s
    #165344
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States peachez

    Tested #88 on D10.2.6 and it fails. Checked out the MR and only difference I can see is that the "){" of the construct method are on the same line in the source code and on a new line in the MR. When applied, the error is thrown as it could not apply and the $request argument doesnt get put in the argument list of the construct() method.
    Im not sure if I can make edits to MRs here (they are a bit new for me in Drupal issues) otherwise I would suggest an edit. Hope this helps

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States peachez

    Here is a patch for BEF 6.0.5 specifically, using the patch from #88. This one accounts for the difference between versions 6.0.5 and 6.0.x with the construct method having the "){" on the same line in 6.0.5 which prevented #88 from applying.
    I wasnt sure how to create a MR against a tag (Im probably missing something super simple) but if its possible, please message me and Ill update this to an MR.

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    Okay, I have been testing both the MR against 6.0.x and the latest patch file (thanks @peachez) against 6.05 and they look good. I have tested both BEF exposed filters in their default UI and altered to use others, like checkboxes and radio buttons. The behaviour of using AJAX to reset the form seems consistent and performant.

    We have had several good iterations now and I believe this is ready for RTBC.

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Can the MR be updated to make sure tests and phpcs run fine.

  • Merge request !78Resolve #2996297 "Attempt again" โ†’ (Merged) created by smustgrave
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
  • Status changed to Fixed 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    And there were a few phpcs errors that needed to be fixed.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine nikita_tt

    Finally! Congratulations!

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia er.garg.karan Chandigarh

    I expected a credit for my patch contribution in #74.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain idiaz.roncero Madrid

    We have found this to be not working with facets. Didn't test it with other exposed filters.

    Basically, the Clear Filters will on first click reload the results via AJAX but keeping the same parameters - so, results are kept unchanged even if the form is cleared - and on second click will finally show all content, unfiltered.

    It is important to note, first, that Drupal core itself does skip the AJAX reload for reset buttons and states that "many things break during the form reset phase if using AJAX" (ajax_view.js).

        // Exclude the reset buttons so no AJAX behaviors are bound. Many things
        // break during the form reset phase if using AJAX.
        const $exposedFormInput = $(
          'input[type=submit], button[type=submit], input[type=image]',
          this.$exposed_form,
        ).not('[data-drupal-selector=edit-reset]');
    

    This code in core is basically skept because of this line that alters the ID and the data-drupal-selector for the reset button, making the .not('[data-drupal-selector=edit-reset]') condition fail.

    $form['actions']['reset']['#id'] = Html::getUniqueId('edit-reset-' . $this->view->storage->id());
    

    So, if you need - as we do - to revert back to the no-AJAX reset button, you can just comment this line as a workaround.

    I think this change needs to be re-reviewed. Should I create a new one or do maintainers prefer to re-open this?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Would open a new one but this has been out for a while so canโ€™t just take it back

Production build 0.71.5 2024