Problem/Motivation

If the default value of the field has a format different as Y-m-d, say a relative like -1 day, or in a common format like m/d/Y, the browser will not populate it.

Before Screenshots


Umami demo site with a new Last Tried date field filter using date popup with relative dates not pre-filled

Proposed Resolution

Create a date from the string and give it format Y-m-d.

After Screenshots


Views date field exposed filter dialog with between operator and relative date -1 month and today


Umami demo site with a Last Tried date field filter using date popup with relative dates pre-filled

Comments

jkevingz created an issue. See original summary.

jkevingz’s picture

StatusFileSize
new1.4 KB

I leave the patch I created for this.

jkevingz’s picture

Status: Active » Needs review
mxmilkiib’s picture

I just tried applying, but I had already applied https://www.drupal.org/project/date_popup/issues/3042555#comment-13825435 to fix error messages, so this patch fails for me with;

error: patch failed: src/DatePopupTrait.php:28
error: src/DatePopupTrait.php: patch does not apply

mxmilkiib’s picture

I manually edited the file with the patch changes and it indeed fixed the display of dates with relative defaults.

mradcliffe’s picture

I was having trouble getting the date to display in the date popup widget even though the patch was functional on a real site.

However I just tested in DrupalPod and I couldn't reproduce my issue with the patch. The patch applied successfully and worked as desired in the following work flows:

Existing view:
1. Create a new view with the desired relative date in a exposed filter.
2. Apply the patch.
3. Clear cache
4. View has the relative dates converted in the date popup input field and the view is filtered by the dates.

New view:
1. Apply the patch.
2. Create a new view with the desired relative date in a exposed filter.
3. View has the relative dates converted in the date popup input field and the view is filtered by the dates.

mradcliffe’s picture

Status: Needs review » Needs work
StatusFileSize
new9.14 KB

I found one issue with the patch.

The "Value Type" radio buttons no longer matter. Regardless of whether I want relative dates or not, it still converts in the actual view.

The change should respect the Value Type setting.

Value type is set for non-relative date format and this still works even though it should probably not.

deffrin’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB

Added a condition for checking whether the "Value Type" is equal to offset to the existing patch. Attached the updated patch.

larowlan’s picture

+++ b/src/DatePopupTrait.php
@@ -2,11 +2,29 @@
+  protected function setDefaultValue(&$default_value) {

I'm not keen on this operating by reference, my preference would be to have it return a value and set that on the item.

Can we also add some type-hinting and return-types here.

mradcliffe’s picture

StatusFileSize
new2.16 KB
new0 bytes

This patch should address @larowlan's comments in #9.

I also re-worded some comments for clarity.

mradcliffe’s picture

StatusFileSize
new2.36 KB
larowlan’s picture

Thanks, I'll give this another look during my contrib contrib office hours next Wed

  • larowlan committed 1d50be3 on 8.x-1.x authored by mradcliffe
    Issue #3129302 by mradcliffe, jkevingz, deffrin, mxmilkiib, larowlan:...
larowlan’s picture

Status: Needs review » Fixed

Thanks folks

larowlan’s picture

This will go out as 8.x-1.2

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.