react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Fields are not rendered in arrayinput with simpleformiterator

Open TomJannes opened this issue 8 years ago • 4 comments

What you were expecting: To see my fields

What happened instead: An empty span is rendered

Steps to reproduce:

        <SimpleForm>
            <ArrayInput source="fases">
                <SimpleFormIterator disableAdd disableRemove>
                    <TextField label="Fase" source="titel" />
                </SimpleFormIterator>
            </ArrayInput>
        </SimpleForm>

does not work but if i change into an input, it works

        <SimpleForm>
            <ArrayInput source="fases">
                <SimpleFormIterator disableAdd disableRemove>
                    <TextInput label="Fase" source="titel" />
                </SimpleFormIterator>
            </ArrayInput>
        </SimpleForm>

The behavior of DateField is the same...

Environment

  • React-admin version: 2.4.1
  • React version: 16.5.2
  • Browser: chrome

TomJannes avatar Nov 05 '18 13:11 TomJannes

Reproduced and confirmed.

SimpleFormIterator overrides the source prop of its children to denote the hierarchy, i.e. it overrides source="titel" by source="fases[0].titel". This is on purpose, because redux-form expects an absolute source for inputs inside array inputs. But fields expect a relative source (relative to the record they receive).

I understand the cause, but I see no simple solution. inputs and fields have to different ways to address their source when they are nested. Changing this behavior will be a BC break.

fzaninotto avatar Nov 05 '18 22:11 fzaninotto

<FormDataConsumer>
  {({getSource, scopedFormData}) => {
      getSource();
      return <TextField source={'fieldName'} record={scopedFormData}/>
    }
  }
</FormDataConsumer>

amayatsky avatar Aug 30 '19 05:08 amayatsky

We won't address that case in core. Making SimpleFormIterator capable of rendering fields natively requires too much added complexity, especially when considering that it can be done in userland with a FormDataConsumer.

I'm re-tagging this issue as a Documentation issue.

fzaninotto avatar Oct 01 '19 09:10 fzaninotto

Fixed by #4477

fzaninotto avatar Mar 05 '20 14:03 fzaninotto