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

Include full record in <AutocompleteInput> and <AutocompleteArrayInput>'s onChange #9245

Merged
merged 9 commits into from
Sep 5, 2023

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Sep 5, 2023

Problem

If we want to react to a change in <AutocompleteInput>'s value, all we can have in onChange is the selected value (i.e. its id in most cases).

If we want to use another field of the selected record, we first need to fetch the record by its id (for instance using useGetOne), which is cumbersome, especially knowing the full record is already available in the ChoicesContext.

Solution

Add a second argument to onChange to pass the full record, which allows the developer to use any field of it.

Technical details

  • This was also implemented in <AutocompleteArrayInput>
  • However I could not implement it in <SelectInput> nor in <SelectArrayInput>, because they both rely on HTML's <select>, which only provides the option's value in event.target.value. It may be still doable by using the ChoicesContext, but I didn't manage to do it for now.

Screencasts

Capture.video.2023-09-05.16.54.31.mp4

@slax57 slax57 added the RFR Ready For Review label Sep 5, 2023
Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@djhi djhi added this to the 4.14.0 milestone Sep 5, 2023
@djhi djhi merged commit 2fc66de into next Sep 5, 2023
@djhi djhi deleted the enhance-AutocompleteInput-onChange branch September 5, 2023 15:16
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