Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get index of SimpleFormIterator

I want to access index of simpleFormIterator. How can I do that? I have a code something like that I'm trying to access it in the SelectInput component

<ArrayInput source='services'>
    <SimpleFormIterator>
        <TextInput source='id' label="Service Name" validate={this.RequiredAndRegex} />
        <FormDataConsumer>
            {({ formData, ...rest }) => 
                <ArrayInput source='parametervalues'>
                    <SimpleFormIterator>
                        <TextInput source='id' label="Parameter Values" validate={this.RequiredAndRegex} />
                        <SelectInput label="Paramater Type"
                            source="id"
                            choices={this.getParameters(formData.services[index].servicetype)}
                            optionText={optionRenderer}
                            optionValue="id" />
                    </SimpleFormIterator>
                </ArrayInput>
            }
        </FormDataConsumer>
    </SimpleFormIterator>
</ArrayInput>
like image 312
Cansel Muti Avatar asked Jun 08 '18 08:06

Cansel Muti


1 Answers

That's not possible with the SimpleFormIterator. You'll have to write your own. I suggest using it as a base (https://github.com/marmelab/react-admin/blob/master/packages/ra-ui-materialui/src/form/SimpleFormIterator.js) and passing the index when cloning the input at L114

like image 162
Gildas Garcia Avatar answered Oct 04 '22 22:10

Gildas Garcia