@@ -93,13 +93,32 @@ const OrderEdit = () => (
93
93
This prop lets you pass a custom element to replace the default Add button.
94
94
95
95
``` jsx
96
- < SimpleFormIterator addButton= {< Button > Add< / Button > }>
96
+ < SimpleFormIterator addButton= {< MyAddButton label = { " Add a line " } / > }>
97
97
< TextInput source= " name" / >
98
98
< NumberInput source= " price" / >
99
99
< NumberInput source= " quantity" / >
100
100
< / SimpleFormIterator>
101
101
```
102
102
103
+ You need to provide an element that triggers the ` add ` function from ` useSimpleFormIterator ` when clicked. Here is an example:
104
+
105
+ ``` jsx
106
+ import { ButtonProps , useSimpleFormIterator , useTranslate } from " react-admin" ;
107
+ import React from " react" ;
108
+ import Button from " @mui/material/Button" ;
109
+
110
+ export const MyAddButton = (props : ButtonProps ) => {
111
+ const { add } = useSimpleFormIterator ();
112
+ const translate = useTranslate ();
113
+
114
+ return (
115
+ < Button onClick= {() => add ()} {... props}>
116
+ {translate (props .label ?? ' ra.action.add' )}
117
+ < / Button>
118
+ );
119
+ };
120
+ ` ` `
121
+
103
122
## ` children`
104
123
105
124
A list of Input elements, that will be rendered on each row.
@@ -294,13 +313,37 @@ Without this prop, `<SimpleFormIterator>` will render one input per line.
294
313
This prop lets you pass a custom element to replace the default Remove button.
295
314
296
315
` ` ` jsx
297
- < SimpleFormIterator removeButton= {< Button > Remove< / Button > }>
316
+ < SimpleFormIterator removeButton= {< MyRemoveButton label = " Remove this line " / > }>
298
317
< TextInput source= " name" / >
299
318
< NumberInput source= " price" / >
300
319
< NumberInput source= " quantity" / >
301
320
< / SimpleFormIterator>
302
321
` ` `
303
322
323
+ You need to provide an element that triggers the ` remove` function from ` useSimpleFormIteratorItem` when clicked. Here is an example:
324
+
325
+ ` ` ` jsx
326
+ import * as React from ' react' ;
327
+ import clsx from ' clsx' ;
328
+ import { ButtonProps , useSimpleFormIteratorItem , useTranslate } from " react-admin" ;
329
+ import Button from " @mui/material/Button" ;
330
+
331
+ export const MyRemoveButton = (props : Omit < ButtonProps , ' onClick' > ) => {
332
+ const { remove } = useSimpleFormIteratorItem ();
333
+ const translate = useTranslate ();
334
+
335
+ return (
336
+ < Button
337
+ onClick= {() => remove ()}
338
+ color= " warning"
339
+ {... props}
340
+ >
341
+ {translate (props .label ?? ' ra.action.remove' )}
342
+ < / Button>
343
+ );
344
+ };
345
+ ` ` `
346
+
304
347
## ` reOrderButtons`
305
348
306
349
This prop lets you pass a custom element to replace the default Up and Down buttons. This custom element must use the ` useSimpleFormIteratorItem` hook to access the current row index and reorder callback.
0 commit comments