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 is shown as null in the backend #747

Closed
arknu opened this issue Mar 15, 2022 · 4 comments
Closed

Date is shown as null in the backend #747

arknu opened this issue Mar 15, 2022 · 4 comments

Comments

@arknu
Copy link

arknu commented Mar 15, 2022

If I add datepicker to form, it works correctly on the frontend. And it stores data correctly (mostly) in the database.

However, when viewing the record in the backend, the value is displayed as null.

This seems to be due to the server sending the date value as "15.03.2022 00.00.00" (I'm on a machine with da-DK locale). This value is what is stored the the JSON in the RecordData column in the UFRecords table. This date format is obviously incorrect, as it should be in ISO format and not a locale-specific format.

This incorrect format then results in the javascript not being able to parse the date value and as a result, null is displayed.

This is a critical issue, as it is corrupting data stored in the database.

Also, why is everything stored twice? The correct dates are stored in EFRecordDataDateTime. So why do we need the JSON as well?

@arknu
Copy link
Author

arknu commented Mar 15, 2022

From looking at the decompiled source (sorry, but when you need to find out whether it is a bug in your code or mine, decompiling is handy), the bug seems to be in the ValuesAsString method on RecordField, which simply calls ToString() on the value. This is going to use the current system locale when formatting the date, which you should never be doing. You are probably also going to be in trouble in other places, with decimal numbers for instance.

I must say I'm surprised to find such a basic mistake in a commercial product. Given that Umbraco is a Danish company, I would at least expect you to test on non en-US locales. I would submit a PR, but obviously I can't do that. So when can I expect this to work correctly?

@AndyButland
Copy link

Yes, it looks like we shouldn't really be doing a ToString() there, but as we have been for some time, it'll be tricky to change that (as any existing form submissions would still have this saved to the JSON representation in the database).

Seems to me we can fix it on the way out though - by parsing back to a date using the current system locale that it will have been serialized with. That then can be formatted client-side, in the way that the current "Created" and "Updated" dates are. We'll look at this for the next release.

As you say the "source of truth" data is saved to UFRecordsDataDateTime. Was before my time by my expectation is the JSON representation was added as a "denormalisation" feature to speed up exports and back-office entry review.

@arknu
Copy link
Author

arknu commented Mar 17, 2022

@AndyButland Thank you for the response. Yeah, that sounds like a sensible solution 👍

By the way, I'm loving all the recent improvements to Forms - makes it a lot easier to work with. Especially the localized backoffice, which I know was a ton of work.

@dcontin-qwerty
Copy link

I have a similar problem.
If I use a Date field on Umbraco Forms is 8.8.0 (on Umbraco 8.16.0), the value is correctly displayed on frontend ed correctly saved on DB, but the date format used on Entry list is wrong.
I see date in forma MM/DD/YYYY and not in DD/MM/YYYY format (my local format and I can't customize it).
With Chrome developer tools I see that, for rendering the value of Date field, is used text.html file located on App_Plugins -> UmbracoForms -> Backoffice -> Common -> RenderTypes
I thinks that the correct file fot Date field is date.html
In this file the value is formatted as date with 'medium' format but I can chage simply the format.

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

No branches or pull requests

3 participants