Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time should not be saved if time is disabled on Date field #3118

Merged
merged 1 commit into from
Jan 19, 2021
Merged

Time should not be saved if time is disabled on Date field #3118

merged 1 commit into from
Jan 19, 2021

Conversation

duncanmcclean
Copy link
Member

This pull request resolves #2497, where the time would always be saved, even if the time_enabled config setting was set to false.

The issue seems to have come from the preProcess function of the Date fieldtype where it was formatting the date value to one that can then be understood by Moment on the frontend.

Essentially, it was just a case of adding a ternary to check if time is enabled, if yes the format will be Y-m-d H:i, otherwise it will be Y-m-d.

@robdekort
Copy link
Contributor

Nice. That seems to do the trick just fine! Saves without time when time_enabled = false and with when it's true.

@sjclark
Copy link
Contributor

sjclark commented Jan 17, 2021

YES! @damcclean you're the hero we need. Really appreciate you taking the time to look into this! ❤️

@duncanmcclean
Copy link
Member Author

YES! @damcclean you're the hero we need. Really appreciate you taking the time to look into this! ❤️

You are very welcome!

@jasonvarga jasonvarga merged commit 436aad7 into statamic:3.0 Jan 19, 2021
@duncanmcclean duncanmcclean deleted the fix/2497 branch January 19, 2021 19:33
@sjclark
Copy link
Contributor

sjclark commented Jan 26, 2021

Hmmmm maybe I spoke to soon, I'm still having the time saved on a field
(this field is just at top level, although having the same issue on a deeper level)

  -
    handle: datetest
    field:
      mode: single
      time_enabled: true
      time_required: false
      earliest_date: '1900-01-01'
      full_width: false
      inline: false
      columns: 1
      rows: 1
      display: DateTEST
      type: date
      icon: date
      listable: hidden

Screen Shot 2021-01-26 at 4 09 33 pm

Opening, reveals:
Screen Shot 2021-01-26 at 4 09 38 pm

Results in:
datetest: '2021-01-21 00:00'

Naturally theres also no way to clear the date, likely due to this bug:
#2920

As far as I can tell theres still no differentiation between time enabled & time required?
Screen Shot 2021-01-26 at 4 14 29 pm

@duncanmcclean
Copy link
Member Author

In the field you shared, you have the time enabled so I'd expect the time to also save.

But basically what you'd like is if there's no time provided in your date and time required is set to false, it should just save the date and no time?

@sjclark
Copy link
Contributor

sjclark commented Jan 26, 2021

@damcclean thanks for your help!

In the field you shared, you have the time enabled so I'd expect the time to also save.

Surely time enabled means that the option to use time is presented, not that its mandatory and will save. I'd expect that to be the option to save, not that you have to save?

But basically what you'd like is if there's no time provided in your date and time required is set to false, it should just save the date and no time?

Essentially I have a date field where the time is sometimes required.

Surely the point of the time enabled versus time required is exactly that situation?

Its totally possible I'm just missing the point of those options?

I'm fairly sure the previous behaviour (in v2) was to show a date field with an "Add Time" button? (possible I'm imagining that?) EDIT: below is the behaviour from v2 - it would show an optional button to add time when you had it enabled
Screen Shot 2021-01-26 at 7 19 01 pm

I'm sure I remember an add time button at some point (maybe earlier in v3?)

@duncanmcclean
Copy link
Member Author

duncanmcclean commented Jan 26, 2021

Yeah, it makes sense, I think I just forgot about that use case.

I'll have a look at PR'ing the code to support the time required setting (after work).

@robdekort
Copy link
Contributor

Oh nice find. Didn't use it either (yet). But def. makes sense to me.

@sjclark
Copy link
Contributor

sjclark commented Jan 26, 2021

Yeah, it makes sense, I think I just forgot about that use case.

I'll have a look at PR'ing the code to support the time required setting (after work).

Amazing! No time stress whatsoever from me! I just appreciate you taking the time to look at it - is all over my head!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date field always saves date including time
4 participants