---
layout: default
title: "Input Components"
---
# Input Components
An `Input` component displays an input, or a dropdown list, a list of radio buttons, etc. Such components allow to edit a record property, and are common in the ``, ``, and `` views.
```jsx
// in src/posts.js
import React from 'react';
import { Edit, SimpleForm, ReferenceInput, SelectInput, TextInput, required } from 'react-admin';
export const PostEdit = (props) => (
} {...props}>
);
```
## Common Input Props
All input components accept the following props:
* `source`: Property name of your entity to view/edit. This attribute is required.
* `label`: Used as input label. Defaults to the humanized `source` when omitted.
* `validate`: Validation rules for the current property. See the [Validation Documentation](./CreateEdit.md#validation) for details.
* `helperText`: Text to be displayed under the input.
* `fullWidth`: If `true`, the input will expand to fill the form width. Defaults to `false`.
```jsx
```
React-admin uses [react-final-form](https://final-form.org/docs/react-final-form/getting-started) to control form inputs. Each input component also accepts all react-final-form [`FieldProps`](https://final-form.org/docs/react-final-form/types/FieldProps), including:
* `initialValue`: Value to be set when the property is `null` or `undefined`.
* `format`: A function that takes the value from the form values and the name of the field and formats the value to give to the input. See the [Transforming Input Value](./Inputs.md#transforming-input-value-tofrom-record) section.
* [`parse`](https://final-form.org/docs/react-final-form/types/FieldProps#parse): A function that takes the value from the input and name of the field and converts the value into the value you want stored as this field's value in the form. See the [Transforming Input Value](./Inputs.md#transforming-input-value-tofrom-record) section.
Additional props are passed down to the underlying component (usually a material-ui component). For instance, when setting the `className` prop on a `TextInput` component, the underlying material-ui `` receives it, and renders with custom styles. You can also set the underlying component `variant` and `margin` that way.
**Tip**: If you edit a record with a complex structure, you can use a path as the `source` parameter. For instance, if the API returns the following 'book' record:
```jsx
{
id: 1234,
title: 'War and Peace',
author: {
firstName: 'Leo',
lastName: 'Tolstoi'
}
}
```
Then you can display a text input to edit the author first name as follows:
```jsx
```
**Tip**: If your interface has to support multiple languages, don't use the `label` prop, and put the localized labels in a dictionary instead. See the [Translation documentation](./Translation.md#translating-resource-and-field-names) for details.
**Tip**: For compatibility reasons, input components also accept the `defaultValue` prop - which is simply copied as the `initialValue` prop.
## ``
To edit arrays of data embedded inside a record, `` creates a list of sub-forms.
```jsx
import { ArrayInput, SimpleFormIterator, DateInput, TextInput } from 'react-admin';
```
![ArrayInput](./img/array-input.png)
`` allows editing of embedded arrays, like the `backlinks` field in the following `post` record:
```js
{
id: 123,
backlinks: [
{
date: '2012-08-10T00:00:00.000Z',
url: 'http://example.com/foo/bar.html',
},
{
date: '2012-08-14T00:00:00.000Z',
url: 'https://blog.johndoe.com/2012/08/12/foobar.html',
}
]
}
```
`` expects a single child, which must be a *form iterator* component. A form iterator is a component accepting a `fields` object as passed by [react-final-form-array](https://github.com/final-form/react-final-form-arrays#fieldarrayrenderprops), and defining a layout for an array of fields. For instance, the `` component displays an array of fields in an unordered list (`
`), one sub-form by list item (`
`). It also provides controls for adding and removing a sub-record (a backlink in this example).
You can pass `disableAdd` and `disableRemove` as props of `SimpleFormIterator`, to disable `ADD` and `REMOVE` button respectively. Default value of both is `false`.
```jsx
import { ArrayInput, SimpleFormIterator, DateInput, TextInput } from 'react-admin';
```
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
To let users choose a value in a list using a dropdown with autocompletion, use ``.
It renders using [downshift](https://github.com/downshift-js/downshift) and a `fuzzySearch` filter.
Set the `choices` attribute to determine the options list (with `id`, `name` tuples).
```jsx
import { AutocompleteInput } from 'react-admin';
```
You can also customize the properties to use for the option name and value, thanks to the `optionText` and `optionValue` attributes:
```jsx
const choices = [
{ _id: 123, full_name: 'Leo Tolstoi', sex: 'M' },
{ _id: 456, full_name: 'Jane Austen', sex: 'F' },
];
```
`optionText` also accepts a function, so you can shape the option text at will:
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
```
The choices are translated by default, so you can use translation identifiers as choices:
```jsx
const choices = [
{ id: 'M', name: 'myroot.gender.male' },
{ id: 'F', name: 'myroot.gender.female' },
];
```
However, in some cases (e.g. inside a ``), you may not want the choice to be translated.
In that case, set the `translateChoice` prop to `false`.
```jsx
```
If you want to limit the initial choices shown to the current value only, you can set the `limitChoicesToValue` prop.
When dealing with a large amount of `choices` you may need to limit the number of suggestions that are rendered in order to maintain usable performance. The `shouldRenderSuggestions` is an optional prop that allows you to set conditions on when to render suggestions. An easy way to improve performance would be to skip rendering until the user has entered 2 or 3 characters in the search box. This lowers the result set significantly, and might be all you need (depending on your data set).
Ex. ` { return val.trim().length > 2 }} />` would not render any suggestions until the 3rd character was entered. This prop is passed to the underlying `react-autosuggest` component and is documented [here](https://github.com/moroshko/react-autosuggest#should-render-suggestions-prop).
`` renders a [material-ui `` component](https://material-ui.com/api/text-field/). Use the `options` attribute to override any of the `` attributes:
{% raw %}
```jsx
```
{% endraw %}
**Tip**: If you want to populate the `choices` attribute with a list of related records, you should decorate `` with [``](#referenceinput), and leave the `choices` empty:
```jsx
import { AutocompleteInput, ReferenceInput } from 'react-admin';
```
Lastly, would you need to override the props of the suggestions container (a `Popper` element), you can specify them using the `options.suggestionsContainerProps`. For example:
{% raw %}
```jsx
```
{% endraw %}
**Tip**: `` is a stateless component, so it only allows to *filter* the list of choices, not to *extend* it. If you need to populate the list of choices based on the result from a `fetch` call (and if [``](#referenceinput) doesn't cover your need), you'll have to [write your own Input component](#writing-your-own-input-component) based on material-ui `` component.
### Properties
| Prop | Required | Type | Default | Description |
| ---|---|---|---|--- |
| `allowEmpty` | Optional | `boolean` | `false` | If `false` and the searchText typed did not match any suggestion, the searchText will revert to the current value when the field is blurred. If `true` and the `searchText` is set to `''` then the field will set the input value to `null`. |
| `choices` | Required | `Object[]` | - | List of items to autosuggest |
| `emptyValue` | Optional | anything | `null` | The value to use for the empty element |
| `emptyText` | Optional | `string` | '' | The text to use for the empty element |
| `matchSuggestion` | Optional | `Function` | - | Required if `optionText` is a React element. Function returning a boolean indicating whether a choice matches the filter. `(filter, choice) => boolean`
| `optionText` | Optional | string | Function | `name` | Fieldname of record to display in the suggestion item or function which accepts the correct record as argument (`(record)=> {string}`) |
| `optionValue` | Optional | `string` | `id` | Fieldname of record containing the value to use as input value |
| `setFilter` | Optional | `Function` | `null` | A callback to inform the `searchText` has changed and new `choices` can be retrieved based on this `searchText`. Signature `searchText => void`. This function is automatically setup when using `ReferenceInput`. |
| `shouldRenderSuggestions` | Optional | Function | `() => true` | A function that returns a `boolean` to determine whether or not suggestions are rendered. Use this when working with large collections of data to improve performance and user experience. This function is passed into the underlying react-autosuggest component. Ex.`(value) => value.trim() > 2` |
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
To let users choose multiple values in a list using a dropdown with autocompletion, use ``.
It renders using [downshift](https://github.com/downshift-js/downshift) and a `fuzzySearch` filter.
Set the `choices` attribute to determine the options list (with `id`, `name` tuples).
```jsx
import { AutocompleteArrayInput } from 'react-admin';
```
You can also customize the properties to use for the option name and value, thanks to the `optionText` and `optionValue` attributes:
```jsx
const choices = [
{ _id: 123, full_name: 'Leo Tolstoi', sex: 'M' },
{ _id: 456, full_name: 'Jane Austen', sex: 'F' },
];
```
`optionText` also accepts a function, so you can shape the option text at will:
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
```
The choices are translated by default, so you can use translation identifiers as choices:
```jsx
const choices = [
{ id: 'M', name: 'myroot.gender.male' },
{ id: 'F', name: 'myroot.gender.female' },
];
```
However, in some cases (e.g. inside a ``), you may not want the choice to be translated. In that case, set the `translateChoice` prop to `false`.
```jsx
```
When dealing with a large amount of `choices` you may need to limit the number of suggestions that are rendered in order to maintain usable performance. The `shouldRenderSuggestions` is an optional prop that allows you to set conditions on when to render suggestions. An easy way to improve performance would be to skip rendering until the user has entered 2 or 3 characters in the search box. This lowers the result set significantly, and might be all you need (depending on your data set).
Ex. ` { return val.trim().length > 2 }} />` would not render any suggestions until the 3rd character was entered. This prop is passed to the underlying `react-autosuggest` component and is documented [here](https://github.com/moroshko/react-autosuggest#should-render-suggestions-prop).
Lastly, `` renders a [material-ui `` component](https://material-ui.com/api/text-field/). Use the `options` attribute to override any of the `` attributes:
{% raw %}
```jsx
```
{% endraw %}
**Tip**: Like many other inputs, `` accept a `fullWidth` prop.
**Tip**: If you want to populate the `choices` attribute with a list of related records, you should decorate `` with [``](#referenceinput), and leave the `choices` empty:
```jsx
import { AutocompleteArrayInput, ReferenceArrayInput } from 'react-admin';
```
If you need to override the props of the suggestions container (a `Popper` element), you can specify them using the `options.suggestionsContainerProps`. For example:
{% raw %}
```jsx
```
{% endraw %}
**Tip**: `` is a stateless component, so it only allows to *filter* the list of choices, not to *extend* it. If you need to populate the list of choices based on the result from a `fetch` call (and if [``](#referencearrayinput) doesn't cover your need), you'll have to [write your own Input component](#writing-your-own-input-component) based on [material-ui-chip-input](https://github.com/TeamWertarbyte/material-ui-chip-input).
**Tip**: React-admin's `` has only a capital A, while material-ui's `` has a capital A and a capital C. Don't mix up the components!
### Properties
| Prop | Required | Type | Default | Description |
| ---|---|---|---|--- |
| `choices` | Required | `Object[]` | - | List of items to autosuggest |
| `matchSuggestion` | Optional | `Function` | - | Required if `optionText` is a React element. Function returning a boolean indicating whether a choice matches the filter. `(filter, choice) => boolean`
| `optionValue` | Optional | `string` | `id` | Fieldname of record containing the value to use as input value |
| `optionText` | Optional | string | Function | `name` | Fieldname of record to display in the suggestion item or function which accepts the current record as argument (`(record)=> {string}`) |
| `setFilter` | Optional | `Function` | `null` | A callback to inform the `searchText` has changed and new `choices` can be retrieved based on this `searchText`. Signature `searchText => void`. This function is automatically setup when using `ReferenceInput`. |
| `shouldRenderSuggestions` | Optional | `Function` | `() => true` | A function that returns a `boolean` to determine whether or not suggestions are rendered. Use this when working with large collections of data to improve performance and user experience. This function is passed into the underlying react-autosuggest component. Ex.`(value) => value.trim() > 2` |
| `source` | Required | `string` | - | Name of field to edit, its type should match the type retrieved from `optionValue` |
| `suggestionLimit` | Optional | `Number` | `null` | Limits the numbers of suggestions that are shown in the dropdown list |
`` also accepts the [common input props](./Inputs.md#common-input-props).
## `` and ``
`` is a toggle button allowing you to attribute a `true` or `false` value to a record field.
```jsx
import { BooleanInput } from 'react-admin';
```
![BooleanInput](./img/boolean-input.png)
This input does not handle `null` values. You would need the `` component if you have to handle non-set booleans.
You can use the `options` prop to pass any option supported by the Material UI `Switch` components. For example, here's how to set a custom checked icon:
{% raw %}
```jsx
import { BooleanInput } from 'react-admin';
import FavoriteIcon from '@material-ui/icons/Favorite';
,
}}
/>
```
{% endraw %}
![CustomBooleanInputCheckIcon](./img/custom-switch-icon.png)
Refer to [Material UI Switch documentation](https://material-ui.com/api/switch) for more details.
`` renders as a dropdown list, allowing to choose between `true`, `false`, and `null` values.
```jsx
import { NullableBooleanInput } from 'react-admin';
```
![NullableBooleanInput](./img/nullable-boolean-input.png)
`` and `` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
If you want to let the user choose multiple values among a list of possible values by showing them all, `` is the right component. Set the `choices` attribute to determine the options (with `id`, `name` tuples):
```jsx
import { CheckboxGroupInput } from 'react-admin';
```
![CheckboxGroupInput](./img/checkbox-group-input.png)
You can also customize the properties to use for the option name and value, thanks to the `optionText` and `optionValue` attributes:
```jsx
const choices = [
{ _id: 123, full_name: 'Leo Tolstoi', sex: 'M' },
{ _id: 456, full_name: 'Jane Austen', sex: 'F' },
];
```
`optionText` also accepts a function, so you can shape the option text at will:
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
```
`optionText` also accepts a React Element, that will be cloned and receive the related choice as the `record` prop. You can use Field components there.
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const FullNameField = ({ record }) => {record.first_name} {record.last_name};
}/>
```
The choices are translated by default, so you can use translation identifiers as choices:
```jsx
const choices = [
{ id: 'programming', name: 'myroot.category.programming' },
{ id: 'lifestyle', name: 'myroot.category.lifestyle' },
{ id: 'photography', name: 'myroot.category.photography' },
];
```
However, in some cases (e.g. inside a ``), you may not want the choice to be translated. In that case, set the `translateChoice` prop to `false`.
```jsx
```
Lastly, use the `options` attribute if you want to override any of Material UI's `` attributes:
{% raw %}
```jsx
import { FavoriteBorder, Favorite } from '@material-ui/icons';
,
checkedIcon:
}} />
```
{% endraw %}
### Properties
| Prop | Type | Default | Description |
| ---|---|---|--- |
| `choices` | Required | `Object[]` | - | List of choices |
| `optionText` | Optional | string | Function | `name` | Fieldname of record to display in the suggestion item or function which accepts the correct record as argument (`(record)=> {string}`) |
| `optionValue` | Optional | `string` | `id` | Fieldname of record containing the value to use as input value |
| `row` | `boolean` | `true` | Display group of elements in a compact row. |
Refer to [Material UI Checkbox documentation](https://material-ui.com/api/checkbox/) for more details.
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
Ideal for editing dates, `` renders an HTML `` element, that most browsers display as a standard [Date Picker](https://material-ui.com/components/pickers/#date-pickers). That means the appearance of `` depends on the browser, and falls back to a text input on Safari. The date formatting in this input depends on the user's locale.
```jsx
import { DateInput } from 'react-admin';
```
![DateInput](./img/date-input.gif)
`` also accepts the [common input props](./Inputs.md#common-input-props).
**Tip**: For a material-ui styled `` component, check out [vascofg/react-admin-date-inputs](https://github.com/vascofg/react-admin-date-inputs).
## ``
An input for editing dates with time. `` renders a standard browser [Date and Time Picker](https://material-ui.com/components/pickers/#date-amp-time-pickers), so the appearance depends on the browser (and falls back to a text input on safari).
```jsx
import { DateTimeInput } from 'react-admin';
```
`` also accepts the [common input props](./Inputs.md#common-input-props).
**Tip**: For a material-ui styled `` component, check out [vascofg/react-admin-date-inputs](https://github.com/vascofg/react-admin-date-inputs).
## ``
`` allows to upload some pictures using [react-dropzone](https://github.com/okonet/react-dropzone).
![ImageInput](./img/image-input.png)
Previews are enabled using `` children, as following:
```jsx
```
Writing a custom field component for displaying the current value(s) is easy: it's a standard [field](./Fields.md#writing-your-own-field-component).
When receiving **new** files, `ImageInput` will add a `rawFile` property to the object passed as the `record` prop of children. This `rawFile` is the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance of the newly added file. This can be useful to display information about size or mimetype inside a custom field.
The `ImageInput` component accepts an `options` prop, allowing to set the [react-dropzone properties](https://react-dropzone.netlify.com/#proptypes). However, some of these props must be passed **directly** to `ImageInput`: `maxSize`, `minSize`, `multiple`.
If the default Dropzone label doesn't fit with your need, you can pass a `placeholder` prop to overwrite it. The value can be anything React can render (`PropTypes.node`):
```jsx
Drop your file here
}>
```
Note that the image upload returns a [File](https://developer.mozilla.org/en/docs/Web/API/File) object. It is your responsibility to handle it depending on your API behavior. You can for instance encode it in base64, or send it as a multi-part form data. Check [this example](./DataProviders.md#extending-a-data-provider-example-of-file-upload) for base64 encoding data by extending the REST Client.
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
`` allows to upload some files using [react-dropzone](https://github.com/okonet/react-dropzone).
![FileInput](./img/file-input.png)
Previews (actually a simple list of files names) are enabled using `` children, as following:
```jsx
```
Writing a custom field component for displaying the current value(s) is easy: it's a standard [field](./Fields.md#writing-your-own-field-component).
When receiving **new** files, `FileInput` will add a `rawFile` property to the object passed as the `record` prop of children. This `rawFile` is the [File](https://developer.mozilla.org/en-US/docs/Web/API/File) instance of the newly added file. This can be useful to display information about size or mimetype inside a custom field.
The `FileInput` component accepts an `options` prop into which you can pass all the [react-dropzone properties](https://react-dropzone.netlify.com/#proptypes). However, some of the most useful props should be passed **directly** on the `FileInput`: `maxSize`, `minSize`, `multiple`.
If the default Dropzone label doesn't fit with your need, you can pass a `placeholder` prop to overwrite it. The value can be anything React can render (`PropTypes.node`):
```jsx
Drop your file here}>
```
Note that the file upload returns a [File](https://developer.mozilla.org/en/docs/Web/API/File) object. It is your responsibility to handle it depending on your API behavior. You can for instance encode it in base64, or send it as a multi-part form data. Check [this example](./DataProviders.md#extending-a-data-provider-example-of-file-upload) for base64 encoding data by extending the REST Client.
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
`` translates to a HTML ``. It is necessary for numeric values because of a [known React bug](https://github.com/facebook/react/issues/1425), which prevents using the more generic [``](#textinput) in that case.
```jsx
import { NumberInput } from 'react-admin';
```
You can customize the `step` props (which defaults to "any"):
```jsx
```
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
If you want to let the user choose a value among a list of possible values that are always shown (instead of hiding them behind a dropdown list, as in [``](#selectinput)), `` is the right component. Set the `choices` attribute to determine the options (with `id`, `name` tuples):
```jsx
import { RadioButtonGroupInput } from 'react-admin';
```
![RadioButtonGroupInput](./img/radio-button-group-input.png)
You can also customize the properties to use for the option name and value, thanks to the `optionText` and `optionValue` attributes:
```jsx
const choices = [
{ _id: 123, full_name: 'Leo Tolstoi', sex: 'M' },
{ _id: 456, full_name: 'Jane Austen', sex: 'F' },
];
```
`optionText` also accepts a function, so you can shape the option text at will:
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const optionRenderer = choice => `${choice.first_name} ${choice.last_name}`;
```
`optionText` also accepts a React Element, that will be cloned and receive the related choice as the `record` prop. You can use Field components there.
```jsx
const choices = [
{ id: 123, first_name: 'Leo', last_name: 'Tolstoi' },
{ id: 456, first_name: 'Jane', last_name: 'Austen' },
];
const FullNameField = ({ record }) => {record.first_name} {record.last_name};
}/>
```
The choices are translated by default, so you can use translation identifiers as choices:
```jsx
const choices = [
{ id: 'M', name: 'myroot.gender.male' },
{ id: 'F', name: 'myroot.gender.female' },
];
```
However, in some cases (e.g. inside a ``), you may not want the choice to be translated. In that case, set the `translateChoice` prop to `false`.
```jsx
```
Lastly, use the `options` attribute if you want to override any of Material UI's `` attributes:
{% raw %}
```jsx
```
{% endraw %}
Refer to [Material UI RadioGroup documentation](https://material-ui.com/api/radio-group) for more details.
**Tip**: If you want to populate the `choices` attribute with a list of related records, you should decorate `` with [``](#referenceinput), and leave the `choices` empty:
```jsx
import { RadioButtonGroupInput, ReferenceInput } from 'react-admin';
```
### Properties
| Prop | Required | Type | Default | Description |
| ---|---|---|---|--- |
| `choices` | Required | `Object[]` | - | List of items to show as options |
| `options` | Optional | Object | Props to pass to the underlying `` element
| `optionText` | Optional | string | Function | `name` | Fieldname of record to display in the suggestion item or function which accepts the current record as argument (`(record)=> {string}`) |
| `optionValue` | Optional | `string` | `id` | Fieldname of record containing the value to use as input value |
| `row` | `boolean` | true | Display options in a compact row. |
| `translateChoice` | Optional | Boolean | `true` | Whether the choices should be translated |
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
Use `` to edit an array of reference values, i.e. to let users choose a list of values (usually foreign keys) from another REST endpoint.
`` fetches the related resources (using `dataProvider.getMany()`) as well as possible resources (using `dataProvider.getList()`) in the reference endpoint.
For instance, if the post object has many tags, a post resource may look like:
```js
{
id: 1234,
tag_ids: [1, 23, 4]
}
```
Then `` would fetch a list of tag resources from these two calls:
```
http://myapi.com/tags?id=[1,23,4]
http://myapi.com/tags?page=1&perPage=25
```
Once it receives the deduplicated reference resources, this component delegates rendering to a subcomponent, to which it passes the possible choices as the `choices` attribute.
This means you can use `` with [``](#selectarrayinput), or with the component of your choice, provided it supports the `choices` attribute.
The component expects a `source` and a `reference` attributes. For instance, to make the `tag_ids` for a `post` editable:
```jsx
import { ReferenceArrayInput, SelectArrayInput } from 'react-admin';
```
![SelectArrayInput](./img/select-array-input.gif)
**Note**: You **must** add a `` for the reference resource - react-admin needs it to fetch the reference data. You can omit the list prop in this reference if you want to hide it in the sidebar menu.
```jsx
```
Set the `allowEmpty` prop when you want to add an empty choice with a value of `null` in the choices list.
Disabling `allowEmpty` does not mean that the input will be required. If you want to make the input required, you must add a validator as indicated in [Validation Documentation](./CreateEdit.md#validation). Enabling the `allowEmpty` props just adds an empty choice (with `null` value) on top of the options, and makes the value nullable.
```jsx
import { ReferenceArrayInput, SelectArrayInput } from 'react-admin';
```
**Tip**: `allowEmpty` is set by default for all Input components children of the `` component
You can tweak how this component fetches the possible values using the `perPage`, `sort`, and `filter` props.
{% raw %}
```jsx
// by default, fetches only the first 25 values. You can extend this limit
// by setting the `perPage` prop.
// by default, orders the possible values by id desc. You can change this order
// by setting the `sort` prop (an object with `field` and `order` properties).
// you can filter the query used to populate the possible values. Use the
// `filter` prop for that.
```
{% endraw %}
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
Use `` for foreign-key values, for instance, to edit the `post_id` of a `comment` resource. This component fetches the related record (using `dataProvider.getMany()`) as well as possible choices (using `dataProvider.getList()` in the reference resource), then delegates rendering to a subcomponent, to which it passes the possible choices as the `choices` attribute.
This means you can use `` with any of [``](#selectinput), [``](#autocompleteinput), or [``](#radiobuttongroupinput), or even with the component of your choice, provided it supports the `choices` attribute.
The component expects a `source` and a `reference` attributes. For instance, to make the `post_id` for a `comment` editable:
```jsx
import { ReferenceInput, SelectInput } from 'react-admin';
```
![ReferenceInput](./img/reference-input.gif)
**Note**: You **must** add a `` for the reference resource - react-admin needs it to fetch the reference data. You *can* omit the `list` prop in this reference if you want to hide it in the sidebar menu.
```jsx
```
**Tip**: Why does `` use the `GET_MANY` verb with a single value `[id]` instead of `GET_ONE` to fetch the record for the current value? Because when there are many `` for the same resource in a form (for instance when inside an ``), react-admin *aggregates* the calls to `GET_MANY` into a single one with `[id1, id2, ...)]`. This speeds up the UI and avoids hitting the API too much.
Set the `allowEmpty` prop when you want to add an empty choice with a value of `null` in the choices list.
Disabling `allowEmpty` does not mean that the input will be required. If you want to make the input required, you must add a validator as indicated in [Validation Documentation](./CreateEdit.md#validation). Enabling the `allowEmpty` props just adds an empty choice (with `null` value) on top of the options, and makes the value nullable.
```jsx
import { ReferenceInput, SelectInput } from 'react-admin';
```
**Tip**: `allowEmpty` is set by default for all Input components children of the `` component:
```jsx
const CommentFilter = (props) => (
// no need for allowEmpty
);
```
You can tweak how this component fetches the possible values using the `perPage`, `sort`, and `filter` props.
{% raw %}
```jsx
// by default, fetches only the first 25 values. You can extend this limit
// by setting the `perPage` prop.
// by default, orders the possible values by id desc. You can change this order
// by setting the `sort` prop (an object with `field` and `order` properties).
// you can filter the query used to populate the possible values. Use the
// `filter` prop for that.
```
{% endraw %}
The child component may further filter results (that's the case, for instance, for ``). ReferenceInput passes a `setFilter` function as prop to its child component. It uses the value to create a filter for the query - by default `{ q: [searchText] }`. You can customize the mapping
`searchText => searchQuery` by setting a custom `filterToQuery` function prop:
```jsx
({ title: searchText })}>
```
The child component receives the following props from ``:
- `loading`: whether the request for possible values is loading or not
- `filter`: the current filter of the request for possible values. Defaults to `{}`.
- `pagination`: the current pagination of the request for possible values. Defaults to `{ page: 1, perPage: 25 }`.
- `sort`: the current sorting of the request for possible values. Defaults to `{ field: 'id', order: 'DESC' }`.
- `error`: the error message if the form validation failed for that input
- `warning`: the warning message if the form validation failed for that input
- `onChange`: function to call when the value changes
- `setFilter`: function to call to update the filter of the request for possible values
- `setPagination`: : function to call to update the pagination of the request for possible values
- `setSort`: function to call to update the sorting of the request for possible values
### Properties
| Prop | Required | Type | Default | Description |
| ---|---|---|---|--- |
| `allowEmpty` | Optional | Boolean | false | If true, add an empty item to the list of choices to allow for empty value |
| `filter` | Optional | Object | `{}` | Permanent filters to use for getting the suggestion list |
| `filterToQuery` | Optional | Function `string => Object` | `searchText => ({ q: [searchText] })` | How to transform the searchText (passed e.g. by an ``) into a parameter for the data provider |
| `perPage` | Optional | number | 25 | Number of suggestions to show |
| `reference` | Required | String | '' | Name of the reference resource, e.g. 'posts'. |
| `sort` | Optional | `{ field: String, order: 'ASC' | 'DESC' }` | `{ field: 'id', order: 'DESC' }` | How to order the list of suggestions |
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
`` is the ideal component if you want to allow your users to edit some HTML contents. It
is powered by [Quill](https://quilljs.com/).
**Note**: Due to its size, `` is not bundled by default with react-admin. You must install it first, using npm:
```sh
npm install ra-input-rich-text
```
Then use it as a normal input component:
```jsx
import RichTextInput from 'ra-input-rich-text';
```
![RichTextInput](./img/rich-text-input.png)
You can customize the rich text editor toolbar using the `toolbar` attribute, as described on the [Quill official toolbar documentation](https://quilljs.com/docs/modules/toolbar/).
```jsx
```
If you need more customization, you can access the quill object through the `configureQuill` callback that will be called just after its initialization.
```jsx
const configureQuill = quill => quill.getModule('toolbar').addHandler('bold', function (value) {
this.quill.format('bold', value)
});
// ...
```
`` also accepts the [common input props](./Inputs.md#common-input-props).
## ``
To let users choose a value in a list using a dropdown, use ``. It renders using [Material ui's `