Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReferenceInput in ArrayInput #9882

Merged
merged 2 commits into from
May 29, 2024
Merged

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented May 29, 2024

Problem

When rendering a ReferenceInput inside an ArrayInput, the current value is never fetched.

Analysis

The current value is grabbed by useReferenceInputController as follows:

const currentValue = useWatch({ name: source });

The problem is, the source is no longer modified by the parent ArrayInput. So when using:

      <ArrayInput source="basket">
        <SimpleFormIterator>
          <ReferenceInput source="product_id" reference="products" />
          <NumberInput source="quantity" />
        </SimpleFormIterator>
      </ArrayInput>

ReferenceInput will get the current value from product_id instead of basket.0.product_id.

cf

const currentValue = useWatch({ name: source });

Solution

Use the useWrappedSource hook

To Do

  • Fix <ReferenceInput>
  • Fix <ReferenceArrayInput>

@slax57 slax57 requested a review from djhi May 29, 2024 14:03
@djhi djhi merged commit 4bc84e5 into next May 29, 2024
14 checks passed
@djhi djhi deleted the fix-referenceinput-in-arrayinput branch May 29, 2024 14:39
@djhi djhi added this to the 5.0.0 milestone May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review v5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants