0

I have a User Resource, which referenced by many other resources.
So I want to create a UserResourceInput :

import React from 'react';
import {ReferenceInput, SelectInput} from 'admin-on-rest';


const UserReferenceInput = (props) => (
    <ReferenceInput reference="user" {...props}>
        <SelectInput optionText="name"/>
    </ReferenceInput>
);
UserReferenceInput.defaultProps = {
    source: 'userId',
    addLabel: true,
    label: 'User'
};

export default UserReferenceInput;

And Use it in simple form like this:

ProductCreate = (props) => (
    <Create {...props}>
        <SimpleForm>
            <TextInput source="title" />
            <NumberInput source="price" />
            <UserReferenceInput />
        </SimpleForm>
    </Create>
);

But I get this Error: enter image description here

1
  • How do you get props from the input ? Commented Sep 29, 2017 at 15:47

1 Answer 1

1

You are missing the source prop on the ReferenceInput. Hence, it can't find value for it. You can define it either inside the UserReferenceInput directly or pass it as prop to the UserReferenceInput in your form.

Edit

Don't use the addLabel prop on the ReferenceInput, it does not support it. Instead, apply it on the SelectInput child.

Sign up to request clarification or add additional context in comments.

2 Comments

The source is in defaultProps.
thanks but addField:true also is needed for it to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.