You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Value to be set when the property is null or undefined
What happened instead:
When the value is null the DateInput ignores the value provided by the initialValue prop.
It does work however when the value is undefined the DateInput component correctly shows the value provided by the initialValue prop.
Steps to reproduce:
Related code:
I have forked the example sandbox and modified the data of the first two posts.
The first post now has null for date published.
The second post now has undefined for date published.
Next, I have adjusted the edit form for a post so that the published_at value now has an initialValue prop with a date.
Where lodash get method is used to get the value for a given property from the record object. However, this only returns the defaultValue if the actual value is 'undefined'. See docs for lodash get method.
The text was updated successfully, but these errors were encountered:
thdk
added a commit
to thdk/react-admin
that referenced
this issue
Jan 24, 2022
null and undefined don't mean the same thing in JS. We should only apply defaultValue if the value is undefined.
Of course, but as the bug report suggests, the documentation explicitly says Value to be set when the property is null or undefined
Maybe this can be taken as a documentation issue.
What you were expecting:
The
DateInput
component should use the value provided by theinitialValue
prop when the value is null or undefined.As state in the docs for the DateInput component:
What happened instead:
When the value is
null
theDateInput
ignores the value provided by theinitialValue
prop.It does work however when the value is
undefined
theDateInput
component correctly shows the value provided by theinitialValue
prop.Steps to reproduce:
Related code:
I have forked the example sandbox and modified the data of the first two posts.
The first post now has
null
for date published.The second post now has
undefined
for date published.Next, I have adjusted the edit form for a post so that the
published_at
value now has aninitialValue
prop with a date.See the sandbox: https://codesandbox.io/s/compassionate-bush-s772t
Click the first post and open the misc. tab. See the value of the published field.
Expected: 01/01/2100
Actual: mm/dd/yyy
Click the second post and open the misc. tab. See the value of the published field.
Expected: 01/01/2100
Actual: 01/01/2100
Other information:
Environment
I have traced down the source code to the following line:
react-admin/packages/ra-core/src/form/useInput.ts
Line 78 in a1c602c
Where lodash
get
method is used to get the value for a given property from the record object. However, this only returns the defaultValue if the actual value is 'undefined'. See docs for lodash get method.The text was updated successfully, but these errors were encountered: