marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.89k stars 5.24k forks source link

ArrayInput issues with nested properties #8256

Closed marhali closed 1 year ago

marhali commented 2 years ago

What you were expecting:

I want to use the ArrayInput with a nested property structure like this:

{
    "numbers": [
        {
            "nested": {
                "number": "10"
            }
        }
    ]
}

What happened instead:

The data gets displayed properly but if I remove an item from the array and want to add a new item, the old data gets displayed. This does not happen if I do not use a nested property for the source parameter. Another problem is the save button which will not display the correct state (enabled, disabled) on nested properties.

Steps to reproduce:

Related code:

See this example with a nested property structure: https://stackblitz.com/edit/github-rmhseu?file=src/data.tsx

<Edit>
    <SimpleForm>
      <ArrayInput source="numbers" defaultValue={[{ nested: { number: 1 } }]}>
        <SimpleFormIterator>
          <NumberInput source="nested.number" defaultValue={1} />
        </SimpleFormIterator>
      </ArrayInput>
    </SimpleForm>
  </Edit>

Other information:

Environment

slax57 commented 2 years ago

Reproduced, thanks!

Might be the implementation of https://github.com/marmelab/react-admin/pull/8204 that only clears objects at depth=1

djhi commented 1 year ago

Cannot reproduce anymore on 4.13.0