React-admin: !Problem ArrayInput > SimpleFormIterator > FormDataConsumer

Created on 25 Feb 2019  路  4Comments  路  Source: marmelab/react-admin

What you were expecting:
I expected that I would be able to select several regions, depending on the selected region (the region id falls into the region filter). And so several times in ArrayInput. It's impossible. See gif.

...
 <ArrayInput source="locations" >
                        <SimpleFormIterator>
                            <ReferenceInput label="resources.User.fields.regionId"  source="regionId" reference="Location" filter={{ type: 'REGION' }} options={{ fullWidth: true }} allowEmpty>
                                <AutocompleteInput suggestionComponent={AddressSuggestionComponent} optionText={choice => `${choice.name} ${choice.typeShort}`}/>
                            </ReferenceInput>
                            <FormDataConsumer>{
                            ({ formData, scopedFormData, ...rest }) =>
                                <ReferenceArrayInput label="resources.User.fields.districtIdOrCityIds" source="districtIdOrCityIds" reference="Location" filter={{ type: 'DISTRICT',  parentIds: (!!scopedFormData && !!scopedFormData.regionId) ? scopedFormData.regionId : null}} options={{ fullWidth: true }} {...rest} >
                                    <AutocompleteArrayInput optionText={optionRenderer} suggestionComponent={AddressSuggestionComponent} {...rest}/>
                                </ReferenceArrayInput>
                            }
                            </FormDataConsumer>
                        </SimpleFormIterator>
                    </ArrayInput>
...

What happened instead:
problem

Other information:
Everything inside FormDataConsumer does not fall into the scopedFormData and formData array.
Environment

  • React-admin version: 2.7.2
  • Last version that did not exhibit the issue (if applicable): ?

Most helpful comment

I know this issue has been closed since a while, but in the docs:
https://marmelab.com/react-admin/Inputs.html#linking-two-inputs
There's an example of this use case. Check this section:

And here is an example usage for getSource inside :

All 4 comments

Can you please write in english ?

sorry

We've never tested using a FormDataConsumer inside a SimpleFormIterator, and we don't want to support that use case (becasue it's compex and uncommon). I suggest you write your own component instead of using ArrayInput.

I know this issue has been closed since a while, but in the docs:
https://marmelab.com/react-admin/Inputs.html#linking-two-inputs
There's an example of this use case. Check this section:

And here is an example usage for getSource inside :

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aserrallerios picture aserrallerios  路  3Comments

waynebloss picture waynebloss  路  3Comments

kopax picture kopax  路  3Comments

marknelissen picture marknelissen  路  3Comments

9747749366 picture 9747749366  路  3Comments