Skip to content

Commit c906526

Browse files
authored
Proofreading
1 parent cbc2812 commit c906526

1 file changed

Lines changed: 24 additions & 33 deletions

File tree

docs/AutocompleteInput.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -387,62 +387,53 @@ 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` is also useful when the choices are records [fetched from another resource](#fetching-choices), and `<AutocompleteInput>` is a child of a [`<ReferenceInput>`](./ReferenceInput.md).
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">`:
391391

392392
```jsx
393393
// in src/PostCreate.jsx
394394
import { AutocompleteInput, Create, ReferenceInput, SimpleForm } from 'react-admin';
395395

396-
export const PostCreate = () => {
397-
return (
398-
<Create>
399-
<SimpleForm>
400-
<ReferenceInput
401-
label="Author"
402-
source="author_id"
403-
reference="authors"
404-
>
405-
<AutocompleteInput />
406-
</ReferenceInput>
407-
</SimpleForm>
408-
</Create>
409-
);
410-
};
396+
export const PostCreate = () => (
397+
<Create>
398+
<SimpleForm>
399+
<ReferenceInput label="Author" source="author_id" reference="authors">
400+
<AutocompleteInput />
401+
</ReferenceInput>
402+
</SimpleForm>
403+
</Create>
404+
);
411405

412406
// in src/App.js
413-
import {Admin, Resource, ListGuesser } from 'react-admin';
407+
import { Admin, Resource, ListGuesser } from 'react-admin';
414408
import { dataProvider } from './dataProvider';
415409
import { PostCreate } from './PostCreate';
416410

417411
export const App = () => (
418412
<Admin dataProvider={dataProvider}>
419413
<Resource name="posts" list={ListGuesser} create={PostCreate} />
420-
<Resource name="authors" recordRepresentation={record => record.name} />
414+
<Resource name="authors" recordRepresentation="name" />
421415
</Admin>
422416
)
423417
```
424418

425-
In that case, react-admin uses the [`recordRepresentation`](./Resource.md#recordrepresentation) of the related resource to display the record label. In the example above, `<AutocompleteInput>` uses the resource representation of the `authors` resource, which is the `name` property.
426-
427-
But if you set the `optionText` prop, react-admin uses it instead of relying on `recordRepresentation`.
419+
If you set the `optionText` prop, react-admin uses it instead of relying on `recordRepresentation`:
428420

429421
```jsx
430422
// in src/PostCreate.jsx
431423
import { AutocompleteInput, Create, ReferenceInput, SimpleForm } from 'react-admin';
432424

433-
export const PostCreate = () => {
434-
return (
435-
<Create>
436-
<SimpleForm>
437-
<ReferenceInput label="Author" source="author_id" reference="authors">
438-
<AutocompleteInput optionText="last_name" />
439-
</ReferenceInput>
440-
</SimpleForm>
441-
</Create>
442-
);
443-
};
425+
export const PostCreate = () => (
426+
<Create>
427+
<SimpleForm>
428+
<ReferenceInput label="Author" source="author_id" reference="authors">
429+
<AutocompleteInput optionText="last_name" />
430+
</ReferenceInput>
431+
</SimpleForm>
432+
</Create>
433+
);
444434
```
445-
In the example above, `<AutocompleteInput>` uses the `last_name` property from `authors` resource instead of their `recordRepresentation`.
435+
436+
Now `<AutocompleteInput>` will use the `last_name` property from `authors` resource instead of `name`.
446437

447438
## `optionValue`
448439

0 commit comments

Comments
 (0)