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

Date field saving format issue in blueprint #5919

Open
ment4list opened this issue Apr 6, 2022 · 8 comments
Open

Date field saving format issue in blueprint #5919

ment4list opened this issue Apr 6, 2022 · 8 comments

Comments

@ment4list
Copy link

With a blueprint like this:

fields:
    releaseYear:
        min: "1800/01/01"
        max: "2022/01/01"
        type: date
        display: YYYY
        format: "Y"

Expectation

What I expect to see is only the year part of the date being saved.

Actual result

It saves correctly to the page's content file but when the page is re-opened in the panel, the date is not the saved year.

If format is simply changed to Y (without quotes), the digit 1 is stored in the content file.

If the format is Ymd, it works. It saves the year, month, and date.

@lukasbestle
Copy link
Member

If format is simply changed to Y (without quotes), the digit 1 is stored in the content file.

This is because the YAML syntax treats the Y as a boolean ("yes") and converts it to true. And the true value is then converted to 1. So it can only work quoted.

[With format: "Y"] It saves correctly to the page's content file but when the page is re-opened in the panel, the date is not the saved year.

I can reproduce this part. If I use the field configuration you posted, the Panel cannot parse the value. For example if I store 2020, the Panel parses and displays that value as 2022. I believe that's because the Vue part of the date field doesn't have a parsing format for just the year.

@distantnative Back when you worked on the refactoring, we discussed deprecating the format option entirely. What is the state of that? I feel that we should always go for the "ISO 8601 without T in the middle" format. There are just too many issues with custom storage formats.

@ment4list There are two possible solutions for your use case:

  • Either store the full date and then use the ->toDate() field method to just print the year.
  • Or use a number field that stores just the four-digit year.

@lukasbestle lukasbestle added the needs: decision 🗳 Requires a decision to proceed label Apr 6, 2022
@distantnative
Copy link
Member

We talked about deprecating format but it would be just too big of breaking change as there is a lot of content out there stored with a custom format. I am surprised though that 2020 reaches the Panel as value - cause there we did say communication between Panel and backend must always happen in "ISO 8601 without T in the middle" format. So if that's the case, then the bug is with the backend not transforming the value from the content file correctly based on the format option before sending it to the Panel.

@distantnative
Copy link
Member

YYYY- actually is in the list that the Panel uses for interpreting dates

@lukasbestle
Copy link
Member

Ah, right. I remember the decision to use the communication format.

I haven't actually checked what the backend sends to be honest. I can only see the Panel displays 2022 with an unsaved changes bar.

@lukasbestle lukasbestle added type: bug 🐛 and removed needs: decision 🗳 Requires a decision to proceed labels Apr 6, 2022
@ment4list
Copy link
Author

@ment4list There are two possible solutions for your use case:

I have chosen to use the number field for my use case which is sufficient.

Thanks for the help.

@lukasbestle
Copy link
Member

Thanks for your feedback, good to hear the workaround works for you.

I'm still reopening this issue because of the bug in the date field.

@lukasbestle lukasbestle reopened this Apr 11, 2022
@distantnative
Copy link
Member

@lukasbestle stumbled upon this issue - shouldn't this be in the kirby repo

@lukasbestle lukasbestle transferred this issue from getkirby/getkirby.com Nov 4, 2023
@lukasbestle
Copy link
Member

lukasbestle commented Nov 4, 2023

Good find. Weird that we haven't transferred it before.

I've tried to reproduce the issue again with v4 beta 3. Current behavior is:

  • The date picker becomes nonfunctional as all dates are disabled and cannot be selected. But I guess for a year, the calendar picker does not fit anyway.
  • Validation works in that a value before 1800 or after 2022 is rejected.
  • Saving the value works as well.
  • After reloading the Panel, the field displays the current year (2023 at the moment). But the form buttons are not displayed (a change to the previous behavior in 3.x).
  • Saving the unchanged form brings up the validation error (because 2023 is not allowed). After closing the validation error dialog, the form buttons are suddenly displayed.

The issue is caused by the field backend. The Fiber data contains the field value as 2023-11-05 00:00:00 (current day) if any non-empty value was stored.

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

No branches or pull requests

3 participants