-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update handling-relations.md with an example of ReferenceArrayInput #1144
base: 2.5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -326,6 +326,15 @@ const ReviewsEdit = props => ( | |||||
> | ||||||
<AutocompleteInput optionText="title" /> | ||||||
</ReferenceInput> | ||||||
// or | ||||||
<ReferenceInput | ||||||
source="book.@id" | ||||||
reference="books" | ||||||
label="Books" | ||||||
filterToQuery={searchText => ({ title: searchText })} | ||||||
> | ||||||
<AutocompleteInput optionText="title" /> | ||||||
</ReferenceInput> | ||||||
|
||||||
<InputGuesser source="rating" /> | ||||||
<InputGuesser source="body" /> | ||||||
|
@@ -345,3 +354,42 @@ export default () => ( | |||||
``` | ||||||
|
||||||
The autocomplete field should now work properly! | ||||||
|
||||||
Let's say `useEmbedded` parameter is set to `true` and you have nested a nested objects array you want to use in an ReferenceArrayInput. ReferenceArrayInput expects an array of ids. In this case you have to tell it, where it finds those ids. This is done via "format" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```javascript | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's better to add this example above than to write again the example. |
||||||
import React from "react"; | ||||||
import { | ||||||
HydraAdmin, | ||||||
ResourceGuesser, | ||||||
CreateGuesser, | ||||||
EditGuesser, | ||||||
InputGuesser | ||||||
} from "@api-platform/admin"; | ||||||
import { ReferenceInput, AutocompleteInput } from "react-admin"; | ||||||
|
||||||
... | ||||||
const BooksEdit = props => ( | ||||||
<EditGuesser {...props}> | ||||||
... | ||||||
|
||||||
<ReferenceArrayInput source="books" reference="books_reference" label="Books" sort={{field: 'title', order: 'ASC'}} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you indent properly? |
||||||
format={v => (v ? v.map(i => (i["@id"] 11? i["@id"] : i)) : [])}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<SelectArrayInput source="title" optionText="title" optionValue="@id"/> | ||||||
</ReferenceArrayInput> | ||||||
... | ||||||
</EditGuesser> | ||||||
); | ||||||
|
||||||
... | ||||||
export default () => ( | ||||||
<HydraAdmin entrypoint={process.env.REACT_APP_API_ENTRYPOINT}> | ||||||
<ResourceGuesser | ||||||
name="books_reference" | ||||||
edit={BooksEdit} | ||||||
... | ||||||
/> | ||||||
</HydraAdmin> | ||||||
); | ||||||
|
||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using the
format
prop is clearer than having this source.