Fix ReferenceField when used inside form #4147
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4124
The bug is a bit tricky: FormInput decorates Field components with Labeled, passing them their props. Then, it renders the Field, passing them the
record
.The problem is that the
record
value forReferenceField
is{}
due todefaultProps
, so it overrides therecord
passed byFormInput
.Then you might ask: how come this used to work in 2.x? Well, my friend, that's because in 2.x we didn't export
ReferenceField
, butwithStyles(styles)(ReferenceField)
, so thedefaultProps
ofReferenceField
were never passed to theLabeled
element...And you might also ask: Why did we need a
defaultValue
in the first place? It probably dates before we usedlodash.get
to get theid
form therecord
, or before theuseGetMany
implementation ignored undefined ids. Anyway, it's no longer necessary in 3.x.