Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When you expose the date field in views and set the operator as "in between".... you can see that the value that you provide in the filter is not carrying forward to the next page.
URL when filter is given:
http://localhost/Drupal8/accounts-report?field_acc_pay_date_value%5Bmin%...
URL after you click the pagination link:
http://localhost/Drupal8/accounts-report?field_acc_pay_date_value%5B0%5D...
You can see that the keyword, min & max is not carried over.
Proposed resolution
Fix views so that date exposed filters work when there is a pager.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#26 | 2987598-11.patch | 8.11 KB | Lendude |
#11 | 2987598-11.patch | 8.11 KB | alexpott |
#11 | 2987598-11.test-only.patch | 6.73 KB | alexpott |
#6 | interdiff_2987598-3-5.txt | 698 bytes | eli-on-drupal |
#6 | tests-2987598-5.patch | 1.38 KB | eli-on-drupal |
Comments
Comment #2
valentinein1027 CreditAttribution: valentinein1027 commentedComment #3
eli-on-drupal CreditAttribution: eli-on-drupal at Mindgrub Technologies commentedComment #4
eli-on-drupal CreditAttribution: eli-on-drupal at Mindgrub Technologies commentedHello! I fixed the problem with this patch.
Comment #6
eli-on-drupal CreditAttribution: eli-on-drupal at Mindgrub Technologies commentedI think that the test that this patch failed should be updated to reflect the new functionality of the exposed form.
Comment #7
ivanhelguera CreditAttribution: ivanhelguera commentedI can confirm both the issue, and the fact that the patch #6 is working.
Comment #8
mmrares CreditAttribution: mmrares at AmeXio commentedComment #9
oksana-c CreditAttribution: oksana-c as a volunteer commentedConfirmed patch in #6 fixes the issue. Marking as RTBC.
Comment #10
alexpottIt'd be great to add an actual test of the bug discovered here. The test change here is related but obviously we've not got test coverage of the specific bug.
Comment #11
alexpottHere's a test.
Comment #12
alexpottAppears to be an alternate fix. I'm not sure what checkboxes have to do with this as we've got no checkboxes exposed. I can;t see how to expose checkboxes - i've tried to expose a checkbox field but that didn't work.
Comment #14
Lendude@alexpott the checkboxes were for when you use Better Exposed Filters, it's not a core thing that broke that put that in. See #2651102: Using checkboxes for exposed filters results in zero rows displaying.
But that added test coverage for the checkbox use case in
\Drupal\Tests\views\Functional\Plugin\ExposedFormCheckboxesTest
, so if that is still green with the alternate fix.....Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI discovered this in #3024672: The views exposed form incorrectly assumes all array based filter values are checkboxes and thus discards all filter values of "0" and @Lendude kindly pointed out this issue.
This is a bit of a red herring, this actually operates on any input value which is an array, so multi-value select lists are also processed by this. So, essentially the implementation in #12 would include all values in a multi-select in the URL, instead of just the ones the user has selected.
For two selected terms, links would look like:
Instead of:
For lists with thousands of terms, this might be an issue.
I really like preserving the keys, like the approach in #11. I also thought that might be viable in #3024672#2, so if that passes the tests, I think that solution works well.
For an equal comparison of this approach, it would mean:
Instead of HEAD, which is:
Comment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedOne issue remains with this whole method: since all array query params are still processed as if they are checkboxes, "0" will never actually be preserved for arrays, regardless of the filter type. So if
?field_date[min]=0
was valid somehow, that would also drop off in the next paginated URL.This is actually broken in the exact same way in HEAD right now and fixing this issue as it is doesn't make it any better or worse, so I think these are actually two bugs with the same chunk of code.
With that in mind, I would suggest we RTBC and fix this, and then repurpose and follow up in #3024672: The views exposed form incorrectly assumes all array based filter values are checkboxes and thus discards all filter values of "0" to dive deeper into the aforementioned issue.
Comment #17
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI have repurposed the other issue to describe the bug in #16: #3024672: The views exposed form incorrectly assumes all array based filter values are checkboxes and thus discards all filter values of "0".
Comment #18
larowlanThe line in question references #342316: Introduce proper Form API #types for 'option' and 'optgroup', and make #options consistent. - however that is a long way off.
I agree with @Sam152s assessment - this doesn't make things any worse but I feel its a bit of a half-way fix. Assuming any array value is a checkbox feels wrong.
I think the size of the patch in #3024672: The views exposed form incorrectly assumes all array based filter values are checkboxes and thus discards all filter values of "0" makes it a candidate for fixing the issue properly here, instead of punting half of it to later.
Thoughts?
Comment #19
alexpott@larowlan I think we should fix separate bugs as we find them - I don't think the size of a patch on another issue should influence whether we combine efforts. They might be related yes but solving them in separate issues is fine.
Comment #20
maxplus CreditAttribution: maxplus commentedHi Alex, I have tested your patch from https://www.drupal.org/project/drupal/issues/2987598#comment-12867202
For my use case it is working perfect. I also enabled Ajax on the view and it keeps working nicely in combination with the pager: the date range filter is keeping its value.
Thanks!
Comment #26
LendudeRe-upping #11 because the test only patch somehow got marked for daily retest, which is useless and annoying
Comment #27
larowlanCommitted fcf5177 and pushed to 8.8.x. Thanks!
c/p to 8.7.x