<Field> initialValue / defaultValue prop
See original GitHub issueAre you submitting a bug report or a feature request?
feature request
What is the current behavior?
A <Form>
is required to be provided initialValues
to set default values for fields.
What is the expected behavior?
<Field>
can accept a prop initialValue
or defaultValue
that is registered with the parent <Form>
's initial values.
This would be oober convenient in many cases where fields are dynamically generated or conditionally rendered in the <Form>
.
I’m happy to work up a PR if you’re accept/review the effort @erikras
Issue Analytics
- State:
- Created 5 years ago
- Reactions:22
- Comments:31 (9 by maintainers)
Top Results From Across the Web
Setting a default value for an Input element in React | bobbyhadz
Pass the default value as a parameter to the useState hook for controlled fields. Set the defaultValue prop on uncontrolled input fields. App.js....
Read more >Final Form Docs – `FieldProps`
The initial value for the field. This value will be used to calculate dirty and pristine by comparing it to the current value...
Read more >React/ReactJS: Difference between defaultValue and value
In React, defaultValue is used with uncontrolled form components whereas value is used with controlled form components. They should not be used together...
Read more >React - change input defaultValue by passing props
You can get around this if you need to by passing a key to the wrapper component, like on your Field or App...
Read more >Uncontrolled Components - React
Component { constructor(props) { super(props); this. ... you often want React to specify the initial value, but leave subsequent updates uncontrolled.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have to agree, I also expected the functionality to be exactly what @crobinson42 and @redbmk expected.
So logic would be something like this: Check if
initialValue
in<Field />
exists?yes
==> use that valueno
==> check ifinitialValues
exists in<Form />
yes
==> use that valueno
==> usedefaultValue
in<Field />
Currently the
defaultValue
will override bothinitialValue
andinitialValues
https://codesandbox.io/s/react-final-form-simple-example-yx7bh
Published a solution in
react-final-form@4.1.0
andfinal-form@4.12.0
. Let me know what you guys think?