react-component / react-component/field-form

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

Open
#303 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
286
Avg merge
4d 16h
Merged PRs (30d)
1

Description

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>
...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example from the issue with the List and Field components, then trace how their names and initial values are handled for object-valued list items. Done means the firstName and age fields map to each user object and the resulting values are handled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.