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

[Doc] Better document <ReferenceOneField emptyText> prop #9562

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion docs/ReferenceOneField.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const BookShow = () => (
| `queryOptions` | Optional | [`UseQueryOptions`](https://tanstack.com/query/v3/docs/react/reference/useQuery) | `{}` | `react-query` client options |
| `sort` | Optional | `{ field: String, order: 'ASC' or 'DESC' }` | `{ field: 'id', order: 'ASC' }` | Used to order referenced records |

`<ReferenceOneField>` also accepts the [common field props](./Fields.md#common-field-props), except `emptyText` (use the child `empty` prop instead).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was probably a bad copy paste from the ReferenceManyField doc

`<ReferenceOneField>` also accepts the [common field props](./Fields.md#common-field-props).

## `children`

Expand All @@ -78,6 +78,24 @@ For instance, if you want to render both the genre and the ISBN for a book:
</ReferenceOneField>
```

## `emptyText`

Use `emptyText` to customize the text displayed when the related record is empty.

```jsx
<ReferenceOneField label="Details" reference="book_details" target="book_id" emptyText="no detail">
<TextField source="genre" /> (<TextField source="ISBN" />)
</ReferenceOneField>
```

`emptyText` also accepts a translation key.

```jsx
<ReferenceOneField label="Details" reference="book_details" target="book_id" emptyText="resources.books.not_found">
<TextField source="genre" /> (<TextField source="ISBN" />)
</ReferenceOneField>
```

## `filter`

You can also use `<ReferenceOneField>` in a one-to-many relationship. In that case, the first record will be displayed. The `filter` prop becomes super useful in that case, as it allows you to select the appropriate record to display.
Expand Down