Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting initial values to dynamic form in antd 4

I have a problem while creating dynamic form in antd4, following this example from docs.

I want to use dynamic form to edit object which already has some values.

In this sandbox I created a new array of initial values: https://codesandbox.io/s/dynamic-form-item-ant-design-demo-slm8o?file=/index.js:636-649

The goal is to achieve this state when opening form:

enter image description here

Grateful for any help.

like image 927
Dmitry Ezhov Avatar asked Jan 01 '23 02:01

Dmitry Ezhov


1 Answers

You need to pass an object to initialValues prop, that contains an array of values for names field list, like so:

    <Form
      name="dynamic_form_item"
      initialValues={{ names: ['', '', ''] }}
      {...formItemLayoutWithOutLabel}
      onFinish={onFinish}
    >
        <Form.List name="names">
            { /* your array of fields goes here */ }
        </Form.List>
    </Form>

like image 155
oozywaters Avatar answered Jan 05 '23 16:01

oozywaters