4

I would like to reuse blocks of input fields. e.g. Use the same group of fields in both Create and Edit forms rather than repeating the code in multiple places.

Documentation shows an example but it uses < Field > elements and trying to use the standard elements like < TextInput > gives errors. https://marmelab.com/blog/2017/01/13/admin-on-rest-0-7.html#use-your-own-component

Is there some scoping issue or something preventing this from working?

I would have expected the following to work fine:

const AddressInputs = (props) => (
    <span>
        <TextField source="address" {...props} />

        {/* Changing from TextField to TextInput gives errors
         /  <TextInput source="address" {...props} />
        */}
    </span>
)

export const ItemEdit = (props) => (
    <Edit {...props}>
        <SimpleForm>
            <AddressInputs />
        </SimpleForm>
    </Edit>
);
pythonjsgeo
  • 5,122
  • 2
  • 34
  • 47

1 Answers1

4

Similar to this

You need to use Field from redux-form to decorate your AOR inputs and use TextField from AOR and pass {...props} as pointed by kunal pareek

import React from 'react';
import {
    LongTextInput,
    ImageField,
    ImageInput,
    TextField
} from 'admin-on-rest';
import { Field } from 'redux-form';


const CustomGroupComp = (props) => (
    <div>
        <TextField source="status" {...props} />
        <Field name="staffComment" component={LongTextInput} label="staffComment" {...props}  />
        <Field name="adminComment" component={LongTextInput}  label="resources.faults.fields.adminComment" {...props} />
        <Field multiple name="fileA" component={ImageInput} accept="image/*">
            <ImageField source="path" title="title"/>
        </Field>
    </div>
);

export default CustomGroupComp;
thodwris
  • 1,327
  • 1
  • 17
  • 27