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
What you were expecting:
Setting a defaultValue={() => uuid()} to a TextInput should work. I'm creating an UuuidInput field, that should by default provide a new uuid. It works if the SimpleForm sets an initialValues function, but that's not what I need.
What happened instead:
The TextInput appears empty inside the SimpleForm.
Steps to reproduce:
Use a SimpleForm with a TextInput
I modified the forked default code sandbox so that he create post form has a titleTextInput field with a string defaultValue and teaser field has a functional defaultValue property. The title works, the teaser field appears empty:
<TextInput autoFocus source="title" defaultValue="static value" />
<TextInput
source="teaser"
defaultValue={() => "value from a function"}
/>
Environment
React-admin version:3.9.0
Last version that did not exhibit the issue (if applicable): -
React version: 16.9.0
Browser: chrome
Stack trace (in case of a JS error): -
The text was updated successfully, but these errors were encountered:
Looking at the react-admin code, this regression seems to be caused by the FormWithRedirect refactoring this regression was caused by the move from redux-form to react-final-form (in 306aef5, released in 3.0, more than a year ago). However, reintroducing this feature (which was introduced by #277 and is documented in CreateEdit.md#per-input-default-value) isn't trivial, and besides it never really worked: we had to inspect Form children, which was never robust.
I think this should be a react-final-form feature, and making it work outside of that lib is too risky.
So I think what we should do here is fix the documentation to remove the ability to pass a custom function as default value.
In your case, you can use the forminitialValues to set the initial value for one field at the form level.
What you were expecting:
Setting a
defaultValue={() => uuid()}
to a TextInput should work. I'm creating an UuuidInput field, that should by default provide a new uuid. It works if theSimpleForm
sets aninitialValues
function, but that's not what I need.What happened instead:
The TextInput appears empty inside the SimpleForm.
Steps to reproduce:
Use a SimpleForm with a TextInput
Related code:
Take a look at https://codesandbox.io/s/intelligent-bartik-km7ed?file=/src/posts/PostCreate.js
I modified the forked default code sandbox so that he create post form has a
title
TextInput
field with a stringdefaultValue
andteaser
field has a functionaldefaultValue
property. Thetitle
works, theteaser
field appears empty:Environment
The text was updated successfully, but these errors were encountered: