Fields are not rendered in arrayinput with simpleformiterator
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
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.
<FormDataConsumer>
{({getSource, scopedFormData}) => {
getSource();
return <TextField source={'fieldName'} record={scopedFormData}/>
}
}
</FormDataConsumer>
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.
Fixed by #4477