Problem/Motivation
The remember feature of exposed filters is not working on some cases because it is not storing values under some circumstances (for example when selecting a non-restrictive option option such as "All").
This behaviour is hidden by the fact the usually the default value for a filter that exposes the "All" option is going to be "All".
To replicate:
1. Setup a view for nodes, and create an exposed filter for the Published field (status) with the following settings: not required, remembered by the authenticated role, default value "NO".
2. Save the view and go to the view's page, the default selected option is "No".
3. Change this to "All" and apply the filter to the view.
3. Refresh the page, the value is not rememberd and back to "NO" which is the default.
The culprit of the issue seems to be in views.inc (_build):
$rc = $handlers[$id]->accept_exposed_input($this->exposed_data);
$handlers[$id]->store_exposed_input($this->exposed_data, $rc);
if (!$rc) {
continue;
}
store_exposed_input will internally only store (and otherwise clear) remembered input if $rc == TRUE.
But $rc is FALSE when the input is supposed not to affect the query (such as selecting the "All" option).
So looks like the logic is overally messed up, and the internals of accept_exposed_input are a bit messy to understand.
Proposed resolution
Pending.
Remaining tasks
Pending.
User interface changes
Pending.
API changes
None.
Original report by cYu
My problem happens when I set up a view with a "Content: Author" relationship, add an exposed filter for "User: Current", set it to non-required with a default value of yes or no, and enable "Remember the last selection".
When using the view and selecting yes or no, the selection will be saved after leaving and returning to the view. When selecting "- Any -" and then leaving and returning to the view, the default value will be selected instead of "- Any -".
This behavior appears to be the same with a simpler example of an exposed filter for "Content: Published" as well.
My temporary solution will be to make "- Any -" the default value, since that gives the appearance of remembering the last selection for each option, but the ideal default would be only showing nodes authored by the current user.
Comments
Comment #1
Ilikejava CreditAttribution: Ilikejava commentedI am having a similar issue. I have a binary field with a checkbox set up as a filter using Better Exposed Filters. I have Remember the Last Selection checked, which works for the default page, but not other pages.
I have other filters set up and it all works like I want it to across all pages in the view. I move from page to page by clicking on a link to the URL. I can't figure out why the filters that are all set up the same way act differently when not on the default page. This one filter happens to be a binary field. The Exposed Form is in a block.
Comment #2
pixelpreview@gmail.com CreditAttribution: pixelpreview@gmail.com commentedI have the same problem with the option "remember the last action"... I must switch to the core select
Comment #3
david_garcia CreditAttribution: david_garcia commentedPossibly related to #1248332: "Remember" feature of exposed filters doesn't work with AJAX and is generally fragile
Comment #4
david_garcia CreditAttribution: david_garcia commentedComment #5
david_garcia CreditAttribution: david_garcia commentedComment #6
david_garcia CreditAttribution: david_garcia commentedProbably this bug is still present in D8, but cannot reproduce because of #2459289: Boolean default values are not saved.
Comment #8
jhedstromComment #18
quietone CreditAttribution: quietone at PreviousNext commentedI tested this on 9.4.x, standard install, and was not able to reproduce this error. I followed the steps given in the Issue Summary.
Therefore, closing as cannot reproduce. If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!