I am struggling with setting the initialValue for the dynamic form field. Lets say we have this example from AntDesign docs.
https://codesandbox.io/s/wonderful-lichterman-br63z?file=/index.js
and the point is, to set the initial value for every newly added fields, in this example i want the "last name" to be set to "kowalski".
following ant design docs :
"In most case, we always recommend to use Form initialValues. Use Item initialValue only when dynamic field usage"
so i was trying to set the initialValue but in result i only get this warning :
"React does not recognize the initialValue
prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase initialvalue
instead. If you accidentally passed it from a parent component, remove it from the DOM element."
thanks for any advice.
I found an easier implementation. Turns out add
method allows one to set field defaultValue
.
<Form.Item>
<Button
type="dashed"
onClick={() => {
add({ lastName: 'mejia', firstName: 'cesar' })
}}
style={{ width: '100%' }}
>
<PlusOutlined /> Add field
</Button>
</Form.Item>
See: https://codesandbox.io/s/fervent-morning-c9vhk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With