Skip to content

Commit a6430c2

Browse files
authored
switched to a more significant example
1 parent c906526 commit a6430c2

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

docs/AutocompleteInput.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
387387

388388
`optionText` also accepts a React Element, that will be rendered inside a [`<RecordContext>`](./useRecordContext.md) using the related choice as the `record` prop. You can use Field components there. However, using an element as `optionText` implies that you also set two more props, `inputText` and `matchSuggestion`. See [Using A Custom Element For Options](#using-a-custom-element-for-options) for more details.
389389

390-
`optionText` can also be useful when the choices are records [fetched from another resource](#fetching-choices), and `<AutocompleteInput>` is a child of a [`<ReferenceInput>`](./ReferenceInput.md). In that case, react-admin uses the [`recordRepresentation`](./Resource.md#recordrepresentation) of the related resource to display the record label. In the example below, `<AutocompleteInput>` renders author options via their `name` attribute, because it's the record representation defined in the `<Resource name="authors">`:
390+
`optionText` can also be useful when the choices are records [fetched from another resource](#fetching-choices), and `<AutocompleteInput>` is a child of a [`<ReferenceInput>`](./ReferenceInput.md). In that case, react-admin uses the [`recordRepresentation`](./Resource.md#recordrepresentation) of the related resource to display the record label. In the example below, `<AutocompleteInput>` renders author options via their `last_name` attribute, because it's the record representation defined in the `<Resource name="authors">`:
391391

392392
```jsx
393393
// in src/PostCreate.jsx
@@ -411,7 +411,7 @@ import { PostCreate } from './PostCreate';
411411
export const App = () => (
412412
<Admin dataProvider={dataProvider}>
413413
<Resource name="posts" list={ListGuesser} create={PostCreate} />
414-
<Resource name="authors" recordRepresentation="name" />
414+
<Resource name="authors" recordRepresentation="last_name" />
415415
</Admin>
416416
)
417417
```
@@ -426,14 +426,14 @@ export const PostCreate = () => (
426426
<Create>
427427
<SimpleForm>
428428
<ReferenceInput label="Author" source="author_id" reference="authors">
429-
<AutocompleteInput optionText="last_name" />
429+
<AutocompleteInput optionText={author => `${author.first_name} ${author.last_name}`} />
430430
</ReferenceInput>
431431
</SimpleForm>
432432
</Create>
433433
);
434434
```
435435

436-
Now `<AutocompleteInput>` will use the `last_name` property from `authors` resource instead of `name`.
436+
Now `<AutocompleteInput>` will render author options using their full name.
437437

438438
## `optionValue`
439439

0 commit comments

Comments
 (0)