React-admin: ReferenceField always display

Created on 4 Oct 2018  路  10Comments  路  Source: marmelab/react-admin

Hello,
thanks you for your project.
I think there is a bug with ReferenceField.
When I use ReferenceField and the source is null, the loading appears but remains indefinitely. I have the impression that the field does not check before if the source is not null.

capture d ecran 2018-10-04 a 15 34 00

I was able to correct this by doing it like that but I think there must be a better solution:

const ConditionalReferenceField = ({ record, ...rest }) =>
  record && record[rest.source] ? (
    <ReferenceField {...rest}>
      <TextField source="name" />
    </ReferenceField>
  ) : null;
  • React-admin version: 2.3.3
  • Last version that did not exhibit the issue (if applicable): no applicable
  • React version: 16.5.2
  • Browser: Chrome
  • Stack trace (in case of a JS error): no

Most helpful comment

I think you can use the allowEmpty={true} attribute on the ReferenceField

All 10 comments

I think you can use the allowEmpty={true} attribute on the ReferenceField

This does not correct the problem. What I want to do is display the reference when the source exists otherwise do not display anything (no loading when there is nothing).

@TomJannes is correct, that's what allowEmpty does on a ReferenceField

I tried with allowEmpty={true} and allowEmpty={false}, but I still have the loading bar although the value is null.

Finally it works, I had to test it badly. Thank you very much! I close this issue.

Why did you close it?

I edited my issue. Finally it works with allowEmpty={true}

I'm reopening the subject, a bug does exist.

When a reference data exists the loading bar is replaced by the data but when it does not find anything the loading bar remains all the time. I don't think that's the way it should be.

capture d ecran 2018-10-08 a 12 05 00

Here, on the first line it does not find any data (infinite loading bar). on the second line, existing data and deleting the loading bar.
Ideally, the loading bar should disappear after a certain period of time without finding any data.

allowEmpty={true} just allows you not to display a loading bar.

Let me reiterate: if a reference data does not exist but you don't allow empty, then your data has a referential integrity problem. React-admin assumes you respect referential integrity, and cannot handle cases when it's not the case...

Closing the issue as won't fix. Feel free to reopen if you disagree.

and by the way, this is probably a duplicate of #854

Refixed in #3550

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yangjiamu picture yangjiamu  路  3Comments

nicgirault picture nicgirault  路  3Comments

aserrallerios picture aserrallerios  路  3Comments

Kmaschta picture Kmaschta  路  3Comments

mbj36 picture mbj36  路  3Comments