I noticed that the default value for fields of type date is "12/30/1969", even without user input and when required is set to
false.
This can be removed and the field can be set to empty by clicking the
Xpresent toward the right hand side of the field.
I was wondering if there was any way the field could be empty by default?
what is looks like after pressing the x button:
maybe it had some restrictions before, you removed them in payload, but they are still applied inside dabatase (you could check independently from payload, via database itself)
on the other hand, maybe "default value" would help you:
{
name: 'orderDate',
label: 'Užsakymo data',
type: 'date',
required: true,
defaultValue: new Date().toLocaleString('lt'),
admin: {
position: 'sidebar',
date: {
displayFormat: 'yyyy-MM-dd',
}
}
},i'm using it to get current date, but maybe something different could be applied with
defaultValuefield
Some date fields do appear as
NULLin the database:
I believe payload changes
NULLdate fields to 0 UTC (1969-12-31) whenever it encounters them, necessitating that the user presses the
Xbutton to revert the field back to NULL.
Setting defaultValue to
undefineddidn't change anything sadly.
When using
date.overridesto pass the
selectedprop as null directly to react-datepicker as such (mentioned here:
https://payloadcms.com/docs/fields/date#display-format-and-picker-appearance):
{
name: "applicationOpens",
type: "date",
required: false,
admin: {
description: "When the application opens",
placeholder: "Select a date",
date: {
overrides: {
selected: null,
}
},
},
},The field does appear empty (shown in the attached image).
Given that the database correctly stores the date as null, and it is not the underlying date picker library (react-datepicker) that is changing the date when encountering null, I believe it must be Payload changing something.
Just doing some digging around in the Payload codebase. I might be completely off the mark here, just throwing some thoughts out.
I don't believe it's this file:
https://github.com/payloadcms/payload/blob/main/packages/ui/src/elements/DatePicker/DatePicker.tsxas it only executes
value && new Date(value),, which should evaluate to
nullif value is
nullAnd I don't think it's this file either:
https://github.com/payloadcms/payload/blob/main/packages/ui/src/fields/DateTime/index.tsxas it just gets the value form useField
maybe
https://github.com/payloadcms/payload/blob/main/packages/ui/src/forms/useField/index.tsx?
Not too sure what fixed it but this issue seems to be resolved in the latest Payload release.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.