Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-admin: handle null on ReferenceFields

Tags:

react-admin

I have a ReferenceField as follows:

<ReferenceField label="User" source="user_id" reference="users">
    <TextField source="name" />
</ReferenceField>

It works nice but the problem is sometimes user_id might be null and that causes the loading bar to be displayed indefinetely. Is there any way that if the value of the reference field is null to display an alternative text or similar?

like image 989
petekaner Avatar asked Jan 27 '23 10:01

petekaner


1 Answers

No, there is no alternative text or something as an option.
Your id being null, should just leave the ReferenceField empty, not displaying loading bar.


Changing your ReferenceField element by adding "allowEmpty" and it should work: <ReferenceField label="User" source="user_id" reference="users" allowEmpty>

like image 156
PanosVl Avatar answered Mar 06 '23 00:03

PanosVl