React-admin: Add Label to <ReferenceField>

Created on 29 Jun 2017  路  4Comments  路  Source: marmelab/react-admin

When using <ReferenceField>, it is rendering fine with <Datagrid> and the right title is added to the column.

However, in <Edit> or <Show>, where it can be useful to make a link to an associated resource, no Label is added to the field and this results in a pretty ugly output :
image

I have the same result whether I add a label="Post" prop to <ReferenceField> or not.

I think this would be good to have a label when it is specified.

Most helpful comment

Define addLabel on the ReferenceField as follows:

    <ReferenceField label="Type" source="id" reference="resource" addLabel>
        <TextField source="field" />
    </ReferenceField>

All 4 comments

Had a same problem. If you add <TextField source="post_id" /> before the <ReferenceField> it looks little bit better :D

Define addLabel on the ReferenceField as follows:

    <ReferenceField label="Type" source="id" reference="resource" addLabel>
        <TextField source="field" />
    </ReferenceField>

Oh gosh I feel dumb, I had read the code and thought that something was not working because it seemed to me that the Label was taken into account in the code but somehow not working.

I understand now that I was missing something.

However, as it wasn't in the Docs, I made a PR to document this prop that apparently many were missing like me !

I have a similar problem now, where in the edit mode I get the label, but in the show mode I don't get the label. I've already added addLabel to my element. Any ideas?

Was this page helpful?
0 / 5 - 0 ratings