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
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 0001-Fix-issue-where-ajax-enabled-views-would-not-properl.patch | 1.7 KB | jacerider |
Comments
Comment #0.0
crea commentedBetter wording
Comment #0.1
crea commentedAdded actions to reproduce
Comment #0.2
crea commentedCorrections
Comment #0.3
crea commentedenglish
Comment #1
crea commentedview::get_exposed_input() could remove own Views parameters passed in AJAX same way it removes "q" and "page" ones.
Comment #2
crea commentedIf 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.
Comment #3
crea commentedComment #4
crea commentedComment #5
tobias.grasse commentedI'm seeing this in the latest 7.x-3.x-dev version, too. Any fix approach for this? Glad to help if I can.
Comment #5.0
tobias.grasse commentedChanged instruction to reproduce
Comment #6
phponwebsites commentedI've also tried this feature in views 7.x-3.11
But there is no results. Same problem occurs again.
Comment #7
shaneod commentedDoesn'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.
Comment #8
Mike Dodd commentedThis is still a problem in drupal 8......
Comment #9
501cGeek commentedIs 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...
Comment #10
BlindPenguin commentedAny 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...
Comment #11
d.sibaud commentedchanged version while the issue still applies on 8.x views
Comment #12
lendudeMoving to the right queue.
Comment #14
yonailoHello 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 :)
Comment #15
yonailoHello,
After some debugging I have found that the issue comes from 'core/modules/views/src/ViewExecutable.php' :
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.
Comment #16
darrenwh commentedFollowing, so are there any solutions for this?
Comment #17
jacerider commentedHere 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.
Comment #19
plousia commentedI 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
Comment #21
chris matthews commentedRan 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.
Comment #25
pameeela commentedClosed #2904491: Views doesn't re-apply its AJAX filters when going back to a page as a duplicate and added contributors to this issue.
Comment #26
pameeela commentedComment #28
keescornelisse commentedAgree 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).
Comment #30
nick hope commentedPatch #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.
Comment #31
pebosi commentedFor me its working when the view has caching disabled.
Comment #32
jglynn commentedWhat 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.
Comment #36
quietone commentedAdding 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
Comment #38
smustgrave commentedSince there hasn't been a follow up to #36 going to close out for now.
If still a bug please reopen.
Thanks all!