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 RadioButtonGroupInput inside ReferenceInput when reference ids are numbers #8229

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Oct 3, 2022

Problem: to merge the possible choices with the current choice, useReferenceInputController checks if the current value is already in the possible values or not (https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/controller/input/useReferenceInputController.ts#L125).
This check only works if id is of type string, because we check it against the current value coming straight from the form (with RHF's useWatch).
In the /story/ra-ui-materialui-input-referenceinput--with-radio-button-group-input story, we use ids that are number, which causes the merge to fail.

Solution: we should compare it with the id of the reference record fetched with useReference, which should be of the matching type

Alternatives:

  • Replace === with == (but I was unsure if this could have undesired side effects)

This PR supersedes #8214

@slax57 slax57 added the RFR Ready For Review label Oct 3, 2022
@fzaninotto fzaninotto merged commit 4a14dbc into master Oct 4, 2022
@fzaninotto fzaninotto deleted the fix-radio-button-2 branch October 4, 2022 07:02
@fzaninotto fzaninotto added this to the 4.4.1 milestone Oct 4, 2022
@fzaninotto fzaninotto changed the title Fix useReferenceInputController all choices merge in case id is not a string Fix RadioButtonGroupInput inside ReferenceInput when reference ids are numbers Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants