If someone wants to clear out the data for a DateTime field in the UI (i.e. set it to null), they should be able to delete the data in the inputs, click "save", and see that the DateTime is no longer set for that field within that document.
Actual/Current behavior
After clicking "Save" after clearing out the existing DateTime value, it appears that the field was cleared out as expected, but when you refresh the page in the UI, the original DateTime value is still set for that field. Also:
Data in the database for that field never gets cleared out or set to null as expected
I looked at the data in both pre-save and pre-validate schema hooks and it would appear that the UI is still sending the original DateTime data to mongoose to save rather than empty fields or null
Steps to reproduce the actual/current behavior
Go to admin UI, edit existing document with a DateTime field set. Set that value to any date/time.
Click "Save". Note that the DateTime field is correctly updated. Refreshing the page shows that the date and time are correctly set.
Go to same record, and remove the date and time strings from both form inputs
Click "Save" again.
Field data should be set to "null" in the database and the fields should be empty in the UI even after a refresh
Instead, the UI makes it look like the data was unset, but if you refresh the page, the original DateTime field returns. Also verified this by looking at the database directly and through console.log dumps in a pre-save and pre-validate hook; instead of empty data, the original timestamp is sent to the database to store.
It's worth noting that the default value (null) is honored. Also, according to the mongoose documentation, "null" (the value, not the string) is a valid value for a DateTime record. The moment an actual date/time is saved to that field, however, it can never be unset.
Right now our workaround for this issue is to set the value of our data to some date in the distant future, i.e. sometime in 2030.
Environment
Software
Version
Keystone
4.2.1
Node.js
10.15.3 (reproducible irrespective of supported node version)
Expected behavior
If someone wants to clear out the data for a DateTime field in the UI (i.e. set it to null), they should be able to delete the data in the inputs, click "save", and see that the DateTime is no longer set for that field within that document.
Actual/Current behavior
After clicking "Save" after clearing out the existing DateTime value, it appears that the field was cleared out as expected, but when you refresh the page in the UI, the original DateTime value is still set for that field. Also:
Steps to reproduce the actual/current behavior
Here's the config for that field in our model:
It's worth noting that the default value (null) is honored. Also, according to the mongoose documentation, "null" (the value, not the string) is a valid value for a DateTime record. The moment an actual date/time is saved to that field, however, it can never be unset.
Right now our workaround for this issue is to set the value of our data to some date in the distant future, i.e. sometime in 2030.
Environment