Skip to content

Commit f8fcd75

Browse files
committed
Update docs
1 parent 52bf4a7 commit f8fcd75

File tree

2 files changed

+38
-4
lines changed
  • packages

2 files changed

+38
-4
lines changed

packages/pf4-component-mapper/src/form-fields/fieldArray/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ArrayItem = ({
3737
<Grid key={ `${field.label}-${index}` } className="ddf-final-form-array-grid">
3838
{ widths.label > 0 &&
3939
<GridItem sm={ widths.label } key={ `${field.label}-${index}` }>
40-
<label htmlFor={ field.name }>{ field.label }</label>
40+
<label htmlFor={ field.name }>{ field.label }{ field.isRequired && <span className='pf-c-form__label-required'>*</span> }</label>
4141
</GridItem> }
4242
<GridItem sm={ widths.field }>
4343
{ formOptions.renderForm([ field ]) }
@@ -90,8 +90,8 @@ const DynamicArray = ({
9090
<FieldArrayProvider key={ rest.input.name } name={ rest.input.name } validate={ arrayValidator }>
9191
{ ({ fields: { map, value = [], push, remove }}) => (
9292
<Fragment>
93-
{ label && <GridItem sm={ 12 }><h3>{ label }</h3></GridItem> }
94-
{ description && <GridItem sm={ 12 }><p>{ description }</p></GridItem> }
93+
{ label && <GridItem sm={ 12 }>{ label }</GridItem> }
94+
{ description && <GridItem sm={ 12 }>{ description }</GridItem> }
9595
{ value.length <= 0 && <Bullseye>
9696
<GridItem sm={ 12 }>{ noItemsMessage }</GridItem>
9797
</Bullseye> }

packages/react-renderer-demo/src/docs-components/field-array.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,40 @@ Each component receives as a prop `FieldArrayProvider`. You can wrap you compone
1313

1414
<RawComponent source="field-array/form-fields-mapper" />
1515

16+
### Naming
17+
18+
FieldArray supports [final form notation](https://final-form.org/docs/final-form/field-names).
19+
20+
Prefix is made by `name` of the `FIELD-ARRAY` component.
21+
22+
Nested components can have custom names, then the values are saved as an array of objects:
23+
24+
```jsx
25+
{
26+
fieldArrayName: [
27+
{
28+
nestedName: 'VALUE 1'
29+
},
30+
{
31+
nestedName: 'VALUE 2'
32+
},
33+
...
34+
]
35+
}
36+
```
37+
38+
You don't need to name the nested components, then the values are saved as an array of values:
39+
40+
```jsx
41+
{
42+
fieldArrayName: [
43+
'VALUE 1',
44+
'VALUE 2',
45+
...
46+
]
47+
}
48+
```
49+
1650
### Validators
1751

1852
You can use user a few provided validators (you can also use your <NavLink to='/renderer/validators'>own</NavLink>.)
@@ -33,7 +67,7 @@ PF4 component mapper provides an experimental implementation of PF4 field arrays
3367
|label|`node`|Label of the array.|
3468
|description|`node`|Description of the array.|
3569
|fields|`array`|A group of fields, which are being added to the array.|
36-
|defaultItem|`any`|Default item which is inserted into a newly created fields group.|
70+
|defaultItem|`any`|Default item which is inserted into a newly created fields group. If you have nested names, don't forget you need to insert an object!|
3771
|minItems|`number`|Remove button is disabled, if the length of the array is equal or smaller.|
3872
|maxItems|`number`|Add button is disabled, if the length of the array is equal or bigger.|
3973
|noItemsMessage|`node`|A message which is shown, when there are no items in the array.|

0 commit comments

Comments
 (0)