Problem/Motivation
First issue:
When using a list field as an exposed grouped filter with the checkbox to remember selections, I get the following error: "An illegal choice has been detected. Please contact the site administrator.":

Filter settings:


Second issue:
When using a Boolean field as an exposed grouped filter with the checkbox to remember selections, I get the following error: "An illegal choice has been detected. Please contact the site administrator.":


Steps to reproduce
Steps to reproduce:
- Import configs
- Add 6 nodes with filled fields (list_field_test: 2(Nodes) - Active, 2 - Inactive, 2 - Locked and test_status: 3 - Published, 3 - Unpublished)
- Go to path /test_list_view
- Select filters:
List Field Test (Inactive), Test Status (Not Published)
or
List Field Test (Inactive), Test Status (- Any -)
- Submit search
- Go to any path
- Again go to path /test_list_view
In different variations of the search query - we get an error:
An illegal choice has been detected. Please contact the site administrator.
Proposed resolution
Added a code for proper select remembered filters with grouped exposed filters
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-2877061
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
blackiceuaComment #3
blackiceuaProposed solution: Not the best, but working
Comment #4
blackiceuaComment #6
blackiceuaFixed. Applies only for BooleanOperator and ListField.
Comment #7
blackiceuaComment #9
blackiceuaAdded use statement for ListField class.
Comment #11
blackiceuaAdded new value with prefix _group to store selected group in a Grouped Filter.
Comment #12
lendude@BlacKICEUA thanks for the report and the patch!
Fix could use some additional comments about what's going on. Also, this really needs some tests.
Comment #13
blackiceuaFixed issue for grouped "string" filters.
Comment #14
blackiceuaComment #17
andrewbelcher commentedI think this can be simplified by just storing the group input value, rather the resulting filter value.
Still needs additional test, but marking for review to check against existing tests.
Comment #18
estoyausenteThe #13 patch works as expected, thanks!
@andrewbelcher , sorry but your patch doesn't work. The error seems resolved (it doesn't be thrown) but the value is not saved correctly or is not showed properly, not sure. Basically, when you select an option in the view, when you move around the site and back again, the saved value is not correctly shown again.
Hi @Lendude I would like to help with the tests but I'm newbie making test, any help to start? Which type of test are necessary? Where can I look for an example?
Thanks!
Comment #20
nick hope commentedPatch #13 also applies and works so far for me in Drupal 8.7.7. Thank you very much @BlacKICEUA. I documented my issue here as a Better Exposed Filters issue.
Comment #21
nick hope commentedPatch #13 cannot be applied if the patches #25, #28 or #29 at https://www.drupal.org/project/drupal/issues/2884296 have been applied as they modify the same file and there is overlap/conflict. And it seems likely that patch #29 will be committed to Drupal 8.9.
Therefore patch #13 here will need to be updated to work after patch #29 there has been applied, or committed. I have tried but unfortunately I don't have the coding skills to sort it out. Any help would be greatly appreciated.
Comment #22
nick hope commentedThe "Undefined index" patch was committed and backported to 8.8.x, so sites that use patch #13 for this issue will break if they update to 8.8.0, released next week on 4th December 2019.
Comment #23
blackiceuaReroll patch for the Drupal ver. 8.8.
Comment #25
toddses commentedAttaching a new patch here, as the patch in #23 resolves the illegal choice issue but does not actually remember the selections, particularly when using Better Exposed Filters checkboxes.
Relevant BEF issue: https://www.drupal.org/project/better_exposed_filters/issues/2935312
This effectively consolidates patch #23 from above and patch #4 in the noted issue.
Comment #26
toddses commentedI've been more deeply testing and the patch in #25 may not resolve all issues - i'm still seeing some quirks when it comes to "remembering" selections and correctly applying the saved values to the forms. Also there's the failing test which I am working to resolve.
Comment #27
toddses commentedAlright I was able to get patch #25 to work as is. However the issue with remembering selections is due to the exposed view block being cached, so I had to add a hook to remove caching on the block.
Comment #28
liquidcms commentedHave a Workflows Field exposed filter which should be a select list but only offers a text field. Use grouped filter to change the filter widget and i then get the Illegal choice error when using filter, leaving the page, returning to the default view.
Tried patch #25 on to 8.8.4 and no longer get Illegal choice, now i get (default, Any):
Warning: array_filter() expects parameter 1 to be array, string given in Drupal\views\ViewExecutable->getExposedInput() (line 716 of core/modules/views/src/ViewExecutable.php).
plus, the filter doesn't return any results (with no errors) when applying any filter value.
Comment #30
rick.kowal commentedI'm getting the same error as @liquidcms when i apply the patch.
Comment #31
akalata commentedIn my testing, removing the changes to ViewExecutable resolves the issues noted in #28.
Comment #33
nick hope commented#31 is identical to #23, so I'm hiding the patch. Also increasing the Drupal version.
I am still getting problems, despite applying #23 or #25.
@toddses Re #27, are your exposed filters in their own block, using https://www.drupal.org/project/views_block_filter_block (or maybe https://www.drupal.org/project/views_exposed_filter_blocks)? Or does that code apply to a regular Views block that has exposed filters in it?
Comment #34
bburgI think this issue started happening for me on a site running 9.2.6 (Or maybe this is a separate issue?). though oddly, it seemed to work fine before I was making some changes to the view. In this case, I am using a date filter, and I have the following configuration:A date field filter
Exposed
Grouped filters enabled
"Optional disabled"
One group with the setting: Greater than or equal, Offset date, "0 minutes"
Another group with the setting: Less than, Offset date, "0 minutes"
So essentially a filter for "Upcoming" or "Past" dates
When I have the "Optional" setting disabled, I get the "An illegal choice has been detected. Please contact the site administrator." error. Which I think is happening because the view isn't respecting that I have the "Upcoming" filter option group set as the default. It instead tries to use the "- Any -" option, which shouldn't be available if there the filter is not set to be optional.
One kicker is that this is a search api view.
Like I said, I may be experiencing a completely different issue, but this seems like it could be similar...
The patch in #31 does not resolve this for me.
I'm going to say nevermind on my whole comment, because I just tested this on a different site with an all-new view, and it seems to work fine.
Comment #36
anacolautti commentedHi! I rerolled patch #31 so that it applies to Drupal 9.3.x correctly.
I just had to apply the changes manually because the lines changed for most of the patch.
I'm not 100% sure about the last part though. I changed from this:
to this:
If someone with more understanding could review this, it would be great. Thanks.
Comment #37
bramdriesenFollowing.
Comment #40
nick hope commentedComment #42
quietone commentedThe related issue has been fixed. so this needs to be re-tested to confirm if is it still a problem.
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 #44
sumit saini commentedThe issue is still present for grouped filters on D9.5.9. So, here is a reroll of the patch in #36.
Comment #45
david.qdoscc commentedI can confirm that this is still an issue as of D10.1.7. Patch #44 applies cleanly and resolves the issue for us.
Comment #46
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #47
rainer f. gottlieb commentedIt does not seem to work for role filter grouping? With 9.5 patch #36 #44 is applied but the error as described above remains, at least in our case. Maybe someone can take another look at this case.
Comment #48
bramdriesenStandard procedure is to fix this on the 11.x branch and then backport to other release branches.
Comment #54
ivnishI rerolled issue fork to 11.x and created MR
I also use this patch in my project and it fixed bug from issue title
Comment #55
smustgrave commentedStill appears to need test coverage
Also can a proposed solution be added to the issue summary please
Thanks!
Comment #56
ivnish@smustgrave
I added a test
I don't know how to name it. "Added some code to fix the bug"? :)
Comment #57
smustgrave commentedThe summary is for the committer and reviewer(s).
Looking at hte code see there is a new check what's it checking? This may help write one https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...
Not adding one will most likely delay the issue until someone wants to get the information the long way.
Comment #58
smustgrave commentedWill keep in review though
Comment #59
ivnishComment #60
ivnishComment #61
krakenbite commentedMR works fine. So I changed status to RTBC
Comment #62
ivnishComment #63
ankitv18 commentedAll I have noticed is that multiple if-else condition with several & operators to check
I think it should be more readable and also there are few suggestions already done on the MR by community, hence moving into NW
Comment #64
ivnishComment #65
smustgrave commentedJust doing some cleanup.
Comment #66
krakenbite commentedMR works fine. So I changed status to RTBC
Comment #67
bramdriesenNot entirely sure #63 was handled. There is still quite a lot of if elseif else nesting being added here which increases the code complexity/readability.
Comment #68
catchYeah I wonder if there's a way to simplify per #67, left a couple of comments on the MR.
Comment #69
gregn0r commentedIt doesn't quite work for me
I have an on/off checkbox filter using BEF and with AJAX enabled
Using the MR it does remember/save the selection - if the box is not checked, I can check it and then reload the page and it stays checked, however if I uncheck the box it does the ajax request and then re-checks the box - I am then unable to change the state once its been saved from being originally checked
There is no other JS interfering with this button
Comment #70
ivnishI improved some code. Please review
Comment #71
bramdriesenLooks a lot better and readable. The test only run fails as expected.
Comment #72
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #73
ivnishComment #74
catchI think we need some additional code comments here to explain what's happening - left a comment on the MR in the place that's still a bit confusing for me.
Comment #75
plopescTested the patch and worked for us. Thank you!
However, we found out some issues that seems unrelated to this issue, though.
For reference, we are facing the issue described in #2742273: Views with "remembered" filters are missing the use cache context for views where cache is enabled and remember is selected.
The view was cached with a specific filter value and selecting a new element does not clear the cache. When the page is reloaded, the original remember value is set for the filter instead of the new one.