Problem/Motivation

Remembered filter values are restored in view::get_exposed_input() function only when there is no input from GET parameters. However, AJAX view rendering always adds lots of parameters, so input is always not empty. Therefore exposed value fallbacks to the one in GET parameter, which doesn't work on initial page load, because remembered filter values are not present in GET until user makes a selection himself.

Steps to reproduce

To reproduce:
1) Create a view with exposed filter and AJAX enabled. Make some filter selection so Views remembers it.
2) Reload the page. View should use remembered filter value.
3) Try to use AJAX pager. On page switch, the filter will reset, because of this bug.
4) If you manually select a value in the filter, all subsequent AJAX page switches will correctly work with the filter, because the filter value will be present in GET.

Proposed resolution

Remaining tasks

Manual testing to confirm if this is still an issue.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

crea’s picture

Issue summary: View changes

Better wording

crea’s picture

Issue summary: View changes

Added actions to reproduce

crea’s picture

Issue summary: View changes

Corrections

crea’s picture

Issue summary: View changes

english

crea’s picture

Title: Remember feature of exposed filters doesn't work with AJAX and is generally fragile » Remembered exposed filters don't work with AJAX

view::get_exposed_input() could remove own Views parameters passed in AJAX same way it removes "q" and "page" ones.

crea’s picture

If it's possible, best option would be to check every filter value. If atleast one is present in GET, treat the input as non-empty.
The current check is too weak: even if we added checks for own Views AJAX parameters, we couldn't account for all possible situations, because GET could contain arbitrary additional parameters used outside of Views, say, by some javascript action. Such additional parameters would break the "remember" feature anyway, unless we change the logics here.

crea’s picture

Title: Remembered exposed filters don't work with AJAX » Remember feature of exposed filters doesn't work with AJAX and is generally fragile
crea’s picture

Title: Remembered exposed filters don't work with AJAX » "Remember" feature of exposed filters doesn't work with AJAX and is generally fragile
tobias.grasse’s picture

I'm seeing this in the latest 7.x-3.x-dev version, too. Any fix approach for this? Glad to help if I can.

tobias.grasse’s picture

Issue summary: View changes

Changed instruction to reproduce

phponwebsites’s picture

Issue summary: View changes

I've also tried this feature in views 7.x-3.11
But there is no results. Same problem occurs again.

shaneod’s picture

Doesn't look like anyone has looked at this for 4 years #6,so i wouldn't get my hopes up that it will be fixed!

If you turn off ajax then edit your exposed filter and check "Remember last selection" the view should remember the selection when you go back.

Mike Dodd’s picture

This is still a problem in drupal 8......

501cGeek’s picture

Is there any workaround for this bug in Drupal 7 so I can still use AJAX and Views exposed filters? Both are important for the app I'm building. Some way to store the filter parameters and resubmit them on page load, like a session, or cookie? Even something that would reset the state of the filter parameters when loading the page, so the state of the filters matched the returned results, would be better than nothing...

BlindPenguin’s picture

Any news for 2018 now? It's still not working properly in version 8. It seems to be remembered properly, but it isn't shown in the ajax Page. Maybe it's just a caching issue...

d.sibaud’s picture

Version: 6.x-2.x-dev » 8.x-3.x-dev

changed version while the issue still applies on 8.x views

lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.6.x-dev
Component: exposed filters » views.module

Moving to the right queue.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yonailo’s picture

Hello yes I can also confirm this issue.

It is easy to reproduce. I was debugging with ?XDEBUG_SESSION_START at the end of the URL, and simply adding this will cause the bug, the remember-me option will stop working :)

yonailo’s picture

Hello,

After some debugging I have found that the issue comes from 'core/modules/views/src/ViewExecutable.php' :

public function getExposedInput() {
     
     [...]

      // If we have no input at all, check for remembered input via session.

      // If filters are not overridden, store the 'remember' settings on the
      // default display. If they are, store them on this display. This way,
      // multiple displays in the same view can share the same filters and
      // remember settings.
      $display_id = ($this->display_handler->isDefaulted('filters')) ? 'default' : $this->current_display;

      if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->storage->id()][$display_id])) {
        $this->exposed_input = $_SESSION['views'][$this->storage->id()][$display_id];
      }
    }

    return $this->exposed_input;
  }

The comment says "If we have no input at all, check for remembered input via session". When there are $_GET parameters which are not 'page' nor 'q' (both of which are removed a little bit before in the code), then $this->exposed_input is not empty and the values from $_SESSION are not used any more.

The question is why $_SESSION values must only be used when there are no other input ? Wouldn't it be possible to merge (possible) $_SESSION values with current $_GET parameters ? in case of conflict, $_GET parameters should take precedence.

Otherwise this bug happens, meaning that $_SESSION information is not recovered and 'remember' settings will be lost on the next page load.

darrenwh’s picture

Following, so are there any solutions for this?

jacerider’s picture

Here is a fix I worked up that seems to work. It basically checks to see if we have ajax request and then skips restoring the values from the session.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

plousia’s picture

I had this same issue and tried the patch in #17. It didn't quite work, it would remember the first value the user chose and that would persist no matter what choices were made after that. This module solved the problem for me and might help someone else: https://www.drupal.org/project/views_ajax_history

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

chris matthews’s picture

Ran across this issue, would be so incredibly helpful if this was fixed in Core so that contrib projects like Better Exposed Filters, Views AJAX History, etc. are not required in order to achieve this functionality.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela credited Calystod.

pameeela credited Mile23.

pameeela’s picture

pameeela’s picture

Issue tags: +Bug Smash Initiative

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

keescornelisse’s picture

Agree with #21, its better to include this contrib projects inside the Drupal core. Its better because its logically to go back to the last current state of the view (when you hit the browser back button).

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nick hope’s picture

Patch #17 will apply to Drupal 9.1.8 but unfortunately it does not solve the problem for me. Nor will the Views AJAX History module. Both together doesn't help either. I just can't get filter "remembering" to work.

pebosi’s picture

For me its working when the view has caching disabled.

jglynn’s picture

What works for me, oddly, is turning off AJAX on the view but still having BEF on. I still get the ajax submits, and don't get the errors with remembering.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs manual testing
Related issues: +#3260652: Feature "Remember the last selection" for views exposed filters doesn't work anymore

Adding related issue that may have fixed this.

The next step here is to confirm that this is still a problem. I am adding the tag for manual testing and updating the Issue Summary to add that as a remaining task.

Cheers

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there hasn't been a follow up to #36 going to close out for now.

If still a bug please reopen.

Thanks all!