Problem/Motivation
I have a view which lists nodes by date. The view uses an exposed filter to let a user select a date range. If the min or max date is missing when the filters are applied, views returns all results.
Steps to reproduce
- Set up a view which exposed a date range filter (operator = "Is Between").
- If both Min & Max date are entered, results are returned within the range selected. If either are missing, all results are returned.
I would expect that Min; No Max would return all results from Min onward and Max; No Min would return all results up to Max. This has caused some of my users some consternation as we are using BEF to automatically trigger an update on filter changes.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | 3202489-32.patch | 8.8 KB | gun_dose |
| #25 | interdiff_18-25.txt | 1.78 KB | suresh prabhu parkala |
| #25 | 3202489-25.patch | 8.8 KB | suresh prabhu parkala |
| #21 | 3202489--after--patch--pic.png | 25.72 KB | vikashsoni |
| #18 | drupal-min-max-date-3202489-17-test-only.patch | 1.84 KB | dsdeiz |
Issue fork drupal-3202489
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
sroy26 commentedPlease find the following patch for the issue.
Comment #3
sroy26 commentedComment #4
bhumikavarshney commentedPatch #2 is nice. Thx for that.
It works for me.
Now, If both Min & Max date are entered, results are returned within the range selected. If either are missing, all results are returned this condition is working as expected.
Comment #5
mitthukumawat commentedPatch #2 applied cleanly on drupal 9.x.3-dev version for me and resolved the issue.
Thanks for the patch.
Comment #6
raphael apard commentedThis is only working if we set MAX with empty MIN.
With MIN set and empty MAX, the condition is "BETWEEN MIN_DATE AND 0" so there is no result.
When only min is set, condition should be ">= $a" and not "BETWEEN $a AND $b"
Comment #7
hhvardan commentedThe patch doesn't work if the min value exists and max is empty.
Comment #8
hhvardan commentedComment #9
hhvardan commentedComment #10
hhvardan commentedComment #11
ranjith_kumar_k_u commentedFixed CS issues
Comment #14
golddragon007 commentedThe patch was not complete, so I added support for datetime module, and not between operations.
And added a related issue from the integer filter variant.
I removed this:
As it makes no sense currently for me, in that moment and time we have a string date, and not a timestamp.
Originates from: https://www.drupal.org/project/drupal/issues/2627512
Comment #15
golddragon007 commentedComment #16
golddragon007 commentedWrong condition fix when both times set.
Comment #17
dsdeiz commentedYeah, works on my end. I've added the tests.
Comment #18
dsdeiz commentedComment #20
dsdeiz commentedComment #21
vikashsoni commentedApplied patch #2 in drupal-9.3.x-dev applied successfully and fix the issue
Thanks for the patch
for ref sharing screenshot...
Comment #22
golddragon007 commented#18 tested and looks fine.
Comment #24
quietone commentedThanks for fixing this.
This needs to be on 10.0.x now, changing version. The patch includes a test so removing tag.
A brief look at the patch and I notices these two items.
I think this should be max.
This comment should now be above the whole if block since it applies to all 3 paths.
I applied the patch to 9.5.x and did some testing. I added a date field to the article content type and then made a view with two exposed filters, one on the added date field and the other on the authored on field. I used devel generated content with authored dates going back for a year. I added a date to two node.
I did not do exhaustive testing. The date field appeared to work with offset and date. The authored on field worked with dates but failed with just a minimum offset. And min offset of '-3 days' failed to show any nodes but a min of '-3 days' and a max of '-2 days' would show the correct nodes.
Setting to NW.
Comment #25
suresh prabhu parkala commentedI tried to fix the changes mentioned in #24. Please have a look.
Comment #26
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
The issue summary needs to be updated with proposed solution.
CI failures in #25
Comment #27
simobm commentedIt's weird, i've tried all of the patches and none seems to works, i've tried on 9.3.22 , 9.4.11 and 9.5.3.
I'm getting the same results as @hhvardan and #Raphael Apard only max works alone, if i use only min i get no results.
Comment #28
camilo.escobar commentedThis issue is also solved in https://www.drupal.org/node/2982968
Comment #29
s3b0un3tHello,
@camilo.escobar : I've try to use your patch in issue #2982968 but it's return an error.
I will add a comment on your issue in order to trace the error.
The patch #25 seems to work on Drupal 10.2.2.
Cheers.
Comment #31
khiminrm commentedPatch from #25 also works for me on Drupal 10.2.6
Comment #32
gun_dose commentedUpdated patch that applies to Drupal 11.2
Comment #36
amanp commentedCreated MR based on 3202489-32.patch. Re-roll for changes in 11.3.9, incorporating #3578444