You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+14-1
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,19 @@
61
61
*[TypeScript] Make types more strict in ra-core, part II ([#9743](https://github.com/marmelab/react-admin/pull/9743)) ([fzaninotto](https://github.com/fzaninotto))
62
62
*[TypeScript] Make types more strict in ra-core ([#9741](https://github.com/marmelab/react-admin/pull/9741)) ([fzaninotto](https://github.com/fzaninotto))
63
63
64
+
## v4.16.18
65
+
66
+
* Fix `<Datagrid>` uses wrong element for "Select All" label ([#9826](https://github.com/marmelab/react-admin/pull/9826)) ([fzaninotto](https://github.com/fzaninotto))
67
+
* Fix `<ListView>` crashes when inside a tab ([#9824](https://github.com/marmelab/react-admin/pull/9824)) ([fzaninotto](https://github.com/fzaninotto))
68
+
* Fix warning about `defaultProps` in React 18.3 ([#9832](https://github.com/marmelab/react-admin/pull/9832)) ([djhi](https://github.com/djhi))
69
+
* Bump ejs from 3.1.8 to 3.1.10 ([#9814](https://github.com/marmelab/react-admin/pull/9814)) ([dependabot bot](https://github.com/dependabot))
70
+
*[Doc] Improve doc for `<Autocomplete onCreate>` and similar props ([#9858](https://github.com/marmelab/react-admin/pull/9858)) ([fzaninotto](https://github.com/fzaninotto))
71
+
*[Doc] Add missing `fetchUtils` import to make custom httpClient snippet clearer in TypeScript ([#9843](https://github.com/marmelab/react-admin/pull/9843)) ([adguernier](https://github.com/adguernier))
72
+
*[Doc] update italian locale reference ([#9830](https://github.com/marmelab/react-admin/pull/9830)) ([christianascone](https://github.com/christianascone))
*[Typescript] Fix compilation error in `<MenuItemLink>`, `<ResettableTextField>` and `<InspectorButton>` with latest `@types/react` ([#9853](https://github.com/marmelab/react-admin/pull/9853)) ([ilia-os](https://github.com/ilia-os))
* Fix combineDataProviders doesn't work when returned by an async function ([#9798](https://github.com/marmelab/react-admin/pull/9798)) ([fzaninotto](https://github.com/fzaninotto))
@@ -72,7 +85,7 @@
72
85
*[Doc] Update third-party Inputs to add link to Google Places AutocompleteInput ([#9771](https://github.com/marmelab/react-admin/pull/9771)) ([quentin-decre](https://github.com/quentin-decre))
73
86
*[Doc] Update `<Search>` and `<SearchWithResult>` to introduce `queryOptions` ([#9779](https://github.com/marmelab/react-admin/pull/9779)) ([erwanMarmelab](https://github.com/erwanMarmelab))
74
87
*[Doc] Update RBAC to better explain the difference between the built-in actions ([#9766](https://github.com/marmelab/react-admin/pull/9766)) ([slax57](https://github.com/slax57))
75
-
*[Doc] Fix `<SimpleForm>` has wrong import for `<RichTextInput>`([#9775](https://github.com/marmelab/react-admin/pull/9775)) ([anthonycmain](https://github.com/anthonycmain))
88
+
*[Doc] Fix `<SimpleForm>` has wrong import for `<RichTextInput>` ([#9775](https://github.com/marmelab/react-admin/pull/9775)) ([anthonycmain](https://github.com/anthonycmain))
76
89
*[Doc] Fix `<RichTextInput>` typo on TipTap ([#9759](https://github.com/marmelab/react-admin/pull/9759)) ([adguernier](https://github.com/adguernier))
77
90
*[Doc] Update `<JsonSchemaForm>` to add details about available widgets ([#9758](https://github.com/marmelab/react-admin/pull/9758)) ([adguernier](https://github.com/adguernier))
78
91
*[TypeScript] Fix warning in `create-react-admin` ([#9728](https://github.com/marmelab/react-admin/pull/9728)) ([hbendev](https://github.com/hbendev))
If you want to customize the label of the "Create XXX" option, use [the `createItemLabel` prop](#createitemlabel).
223
+
222
224
If you just need to ask users for a single string to create the new option, you can use [the `onCreate` prop](#oncreate) instead.
223
225
226
+
## `createLabel`
227
+
228
+
When you set the `create` or `onCreate` prop, `<AutocompleteInput>` lets users create new options. By default, it renders a "Create" menu item at the bottom of the list. You can customize the label of that menu item by setting a custom translation for the `ra.action.create` key in the translation files.
Or, if you want to customize it just for this `<AutocompleteInput>`, use the `createLabel` prop:
233
+
234
+
You can customize the label of that menu item by setting a custom translation for the `ra.action.create` key in the translation files.
235
+
236
+
```jsx
237
+
<AutocompleteInput
238
+
source="author"
239
+
choices={authors}
240
+
onCreate={onCreate}
241
+
createLabel="Start typing to create a new item"
242
+
/>
243
+
```
244
+
245
+
## `createItemLabel`
246
+
247
+
If you set the `create` or `onCreate` prop, `<AutocompleteInput>` lets users create new options. When the text entered by the user doesn't match any option, the input renders a "Create XXX" menu item at the bottom of the list.
You can customize the label of that menu item by setting a custom translation for the `ra.action.create_item` key in the translation files.
252
+
253
+
Or, if you want to customize it just for this `<AutocompleteInput>`, use the `createItemLabel` prop:
254
+
255
+
```jsx
256
+
<AutocompleteInput
257
+
source="author"
258
+
choices={authors}
259
+
onCreate={onCreate}
260
+
createItemLabel="Add a new author: %{item}"
261
+
/>
262
+
```
263
+
224
264
## `debounce`
225
265
226
266
When used inside a [`<ReferenceInput>`](./ReferenceInput.md), `<AutocompleteInput>` will call `dataProvider.getList()` with the current input value as filter after a delay of 250ms. This is to avoid calling the API too often while users are typing their query.
@@ -367,39 +407,50 @@ const BookCreate = () => (
367
407
368
408
## `onCreate`
369
409
370
-
Use the `onCreate` prop to allow users to create new options on-the-fly. Its value must be a function. This lets you render a `prompt` to ask users about the new value. You can return either the new choice directly or a Promise resolving to the new choice.
410
+
Use the `onCreate` prop to allow users to create new options on the fly. This is equivalent to MUI's `<AutoComplete freeSolo>` prop.
`onCreate` must be a function that adds a new choice and returns it. This function can be async. The added choice must use the same format as the other choices (usually `{ id, name }`).
418
+
419
+
In the following example, users can create a new company by typing its name in the `<AutocompleteInput>`:
If a prompt is not enough, you can use [the `create` prop](#create) to render a custom component instead.
449
+
If you want to customize the label of the "Create XXX" option, use [the `createItemLabel` prop](#createitemlabel).
450
+
451
+
When used inside a `<ReferenceInput>`, the `onCreate` prop should create a new record in the reference resource, and return it. See [Creating a New Reference](./ReferenceInput.md#creating-a-new-reference) for more details.
452
+
453
+
If a function is not enough, you can use [the `create` prop](#create) to render a custom component instead.
Copy file name to clipboardExpand all lines: docs/CreateReactAdmin.md
+2
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@ title: "The create-react-admin CLI"
7
7
8
8
`create-react-admin` is a package that generates a react-admin app scaffolding using [Vite](https://vitejs.dev/). It is designed to work on most setups and produces predictable and consistent results. It's the preferred way to create a new react-admin application.
Copy file name to clipboardExpand all lines: docs/Fields.md
+12-14
Original file line number
Diff line number
Diff line change
@@ -288,18 +288,19 @@ And see [the Material UI system documentation](https://mui.com/system/the-sx-pro
288
288
289
289
This prop defines the text alignment of the field when rendered inside a `<Datagrid>` cell. By default, datagrid values are left-aligned ; for numeric values, it's often better to right-align them. Set `textAlign` to `right` for that.
290
290
291
-
[`<NumberField>`](./NumberField.md) already uses `textAlign="right"`. Set the default value for this prop if you create a custom numeric field.
292
-
293
291
```jsx
294
-
constBasketTotal= () => {
295
-
constrecord=useRecordContext();
296
-
if (!record) returnnull;
297
-
consttotal=record.items.reduce((total, item) => total +item.price, 0);
Copy file name to clipboardExpand all lines: docs/ReferenceInput.md
+84-26
Original file line number
Diff line number
Diff line change
@@ -166,32 +166,6 @@ You can filter the query used to populate the possible values. Use the `filter`
166
166
167
167
**Note**: When users type a search term in the `<AutocompleteInput>`, this doesn't affect the `filter` prop. Check the [Customizing the filter query](#customizing-the-filter-query) section below for details on how that filter works.
168
168
169
-
## `format`
170
-
171
-
By default, children of `<ReferenceInput>` transform `null` values from the `dataProvider` into empty strings.
172
-
173
-
If you want to change this behavior, you have to pass a custom `format` prop to the `<ReferenceInput>`*child component*, because **`<ReferenceInput>` doesn't have a `format` prop**. It is the responsibility of the child component to format the input value.
174
-
175
-
For instance, if you want to transform an option value before rendering, and the selection control is an `<AutocompleteInput>` (the default), set [the `<AutocompleteInput format>` prop](./Inputs.md#format) as follows:
<SelectInput format={value=> value ===undefined?'not defined':null} />
192
-
</ReferenceInput>
193
-
```
194
-
195
169
## `label`
196
170
197
171
In an `<Edit>` or `<Create>` view, the `label` prop has no effect. `<ReferenceInput>` has no label, it simply renders its child (an `<AutocompleteInput>` by default). If you need to customize the label, set the `label` prop on the child element:
@@ -327,6 +301,32 @@ Then to display a selector for the contact company, you should call `<ReferenceI
By default, children of `<ReferenceInput>` transform `null` values from the `dataProvider` into empty strings.
307
+
308
+
If you want to change this behavior, you have to pass a custom `format` prop to the `<ReferenceInput>`*child component*, because `<ReferenceInput>` doesn't have a `format` prop. It is the responsibility of the child component to format the input value.
309
+
310
+
For instance, if you want to transform an option value before rendering, and the selection control is an `<AutocompleteInput>` (the default), set [the `<AutocompleteInput format>` prop](./Inputs.md#format) as follows:
<SelectInput format={value=> value ===undefined?'not defined':null} />
327
+
</ReferenceInput>
328
+
```
329
+
330
330
## Customizing The Filter Query
331
331
332
332
By default, `<ReferenceInput>` renders an `<AutocompleteInput>`, which lets users type a search term to filter the possible values. `<ReferenceInput>` calls `dataProvider.getList()` using the search term as filter, using the format `filter: { q: [search term] }`.
When users don't find the reference they are looking for in the list of possible values, they need to create a new reference. If they have to quit the current form to create the reference, they may lose the data they have already entered. So a common feature for `<ReferenceInput>` is to let users create a new reference on the fly.
Children of `<ReferenceInput>` (`<AutocompleteInput>`, `<SelectInput>`, etc.) allow the creation of new choices via the `onCreate` prop. This displays a new "Create new" option in the list of choices. You can leverage this capability to create a new reference record.
351
+
352
+
The following example is a contact edition form using a `<ReferenceInput>` to select the contact company. Its child `<AutocompleteInput onCreate>` allows to create a new company on the fly if it doesn't exist yet.
In the example above, the `handleCreateCompany` function creates a new company with the name provided by the user, and returns it so that `<AutocompleteInput>` selects it.
389
+
390
+
You can learn more about the `onCreate` prop in the documentation of the selection input components:
If you need to ask the user for more details about the new reference, you display a custom element (e.g. a dialog) when the user selects the "Create" option. use the `create` prop for that instead of `onCreate`.
396
+
397
+
You can learn more about the `create` prop in the documentation of the selection input components:
0 commit comments