I just fix a problem about "An illegal choice has been detected..." with module "better_exposed_filters"
Configuration :
- Module "better_exposed_filters" installed
- Create a view
- Expose a filter as collapsible checkbox with better exposed filter
- Check the filter option remember
Then go to your view
- Check one checkbox on the collapsible list and then submit (it work perfectly)
- Go to another page and come back to your view (or actualize the page)
- Then an error appear with message "An illegal choice has been detected..."
- As you can see, all checkboxes are checked
The bug came from the class "Drupal\views\Plugin\views\filter\FilterPluginBase"
To fix it, open the file and replace last line from the method : "storeExposedInput"
=> you must remove integer values : 0
$session[$this->options['expose']['identifier']] = $input[$this->options['expose']['identifier']];
TO
// Fix multiple checkbox (Illegal Choice has been detected)
$value = $input[$this->options['expose']['identifier']];
if($this->options['expose']['multiple'] && is_array($value)){
$value = array_filter($value, function($value) {
return $value !== 0;
});
}
$session[$this->options['expose']['identifier']] = $value;
Sorry, but I can't make a pull request right now, but I hope it will help
Comments
Comment #2
mustanggb commentedComment #4
elamanConfirming the issue.
Using
array_filterwithout any argument, should get rid of empty items in array. Here is the patch.Comment #5
borisson_Can we reproduce this with drupal core only? We should add tests so that this problem doesn't reappear in the future.
Comment #7
duneblIt looks like it is solving my problem with drupal core only:
Field exposed= floating number
Exposed filter type=unique
Operator=Is equal
Expose operator= yes
Hunk #1 succeeded at 1464 (offset -12 lines).Comment #8
dunebl#4 apply on 8.8.2 with offset
Comment #10
nimoatwoodway#4 works for me against 8.8.5
Comment #11
hardik_patel_12 commentedRe roll for 8.8.x-dev.
Comment #12
lendudeComment #13
mrinalini9 commentedRerolled patch to 8.8.x as #11 failed to apply.
Comment #14
hardik_patel_12 commentedComment #16
lance lancelot commentedI tried to fix this bug with the above patches, but then there is always one item selected.
In addition to this I just set the array to NULL and that seems to be working for me:
Comment #17
dystopianblue commentedPatch in #13 fixed the error msg for me. Thanks!
Comment #19
duneblpatch #13 failed on 9.4:
Comment #21
davidxoRerolled #13 for 9.3.x
Comment #23
smustgrave commentedWonder if #2568889: Views exposed text filter set to required shows an empty error and form error on page load solved this issue?
If not please reopen in "needs work" as it was tagged for tests.
Comment #25
smustgrave commentedSince there hasn't been a follow up going to close for now. If still a valid bug please reopen.
Thanks all!