field-form icon indicating copy to clipboard operation
field-form copied to clipboard

How use List with object values and mapped to fields form?

Open astranavt opened this issue 4 years ago • 1 comments

When using a list where each item contains two fields you cannot use the object keys corresponding to the form fields

Example of how I tried and failed

  const initialValues = [
    { firstName: 'test', age: 100 },
    { firstName: 'test2', age: 110 },
  ];

...
  <List name="users" initialValue={initialValues}>
          {(fields, { add, remove }, { errors }) => {
            return fields.map((field, index) => (
              <>
                <Field name="firstName" initialValue={initialValues[field.key].firstName}>
                  <input />
                </Field>
                <Field name="age">
                  <input />
                </Field>
              </>
            ));
          }}
        </List>
...

astranavt avatar May 30 '21 06:05 astranavt

bump

fax1ty avatar Mar 17 '22 17:03 fax1ty