react-admin
react-admin copied to clipboard
Handle error for values of invalid data types in DateField
This PR proposes changes to handle the scenario when the DateField value does not match the type criteria to be handled as a Date.
Current behavior causes an error when trying to execute date.toLocaleString()
on an undefined date value.
DateField.tsx:99 Uncaught TypeError: Cannot read properties of undefined (reading 'toLocaleString')
at DateFieldImpl (DateField.tsx:99:20)
at renderWithHooks (react-dom.development.js:16305:18)
at updateFunctionComponent (react-dom.development.js:19588:20)
at updateSimpleMemoComponent (react-dom.development.js:19425:10)
at updateMemoComponent (react-dom.development.js:19284:14)
at beginWork (react-dom.development.js:21673:16)
at HTMLUnknownElement.callCallback2 (react-dom.development.js:4164:14)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)
at invokeGuardedCallback (react-dom.development.js:4277:31)
at beginWork$1 (react-dom.development.js:27451:7)
@fzaninotto That's a good question indeed. I guess it can't hurt to introduce a new "invalid value" message, which will help both the developer (to see that there is an issue with the data) and the user (to avoid having a runtime error and a blank value).
In all the react-admin fields, only two render a different output in case of error: ReferenceField and ReferenceManyCount.
I think it's a good thing to show to the user that the value is invalid, so I'd recommend we do the same for invalid dates in DateField. In that case, the field could render the same ErrorIcon as ReferenceField.