Skip to content

Commit 72f0060

Browse files
committed
Added docs for deleted value.
1 parent 273678c commit 72f0060

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Grid from '@material-ui/core/Grid'
2+
import RawComponent from '@docs/raw-component';
3+
4+
import ListOfContents from '../../src/helpers/list-of-contents';
5+
6+
<Grid container item>
7+
<Grid item xs={12} md={10}>
8+
9+
# Deleted value
10+
11+
If you required a specific value for a field which had **initialValue** to set it to some specific value. For instance if you have a form which edits some entity and you need to delete some attribute, APIs usually require the value to be set to `null` to register the change.
12+
13+
14+
<RawComponent source="deleted-value" />
15+
16+
</Grid>
17+
<Grid item xs={false} md={2}>
18+
<ListOfContents file="renderer/deleted-value" />
19+
</Grid>
20+
</Grid>

packages/react-renderer-demo/src/app/pages/renderer/renderer-api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Form Renderer provides a lot of customization via props.
3131
|<RouterLink href="/renderer/form-controls"><Link>renderFormButtons</Link></RouterLink>|one of `[node, element, func]`|You can provide your own form buttons component. This component will receive all needed props.||
3232
|<RouterLink href="/renderer/unmounting"><Link>clearOnUnmount</Link></RouterLink>|bool|Will clear values of unmounted components. You can also set this to specific component in the form schema.|false|
3333
|canReset|bool|Show/hide reset button.|false|
34+
|<RouterLink href="/renderer/deleted-value"><Link>deletedValue</Link></RouterLink>|any|Value that will be set to field with **initialValue** after deleting it. Useful for forms while editing.|undefined|
3435
|onReset|func|A reset callback. You don't need to manually clear the form values!||
3536
|onCancel|func|A cancel callback, which receives `values` as the first argument.||
3637
|onStateUpdate|func|A function which will be called with every form update, i.e. `({ values }) => setValues(values)`||

packages/react-renderer-demo/src/app/src/components/navigation/documentation-pages.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const docs = [{
3131
}, {
3232
component: 'data-types',
3333
linkText: 'Data types',
34+
}, {
35+
component: 'deleted-value',
36+
linkText: 'Empty field value',
3437
}, {
3538
component: 'field-provider',
3639
linkText: 'Custom components',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useState } from 'react';
2+
import FormRenderer, { componentTypes } from '@data-driven-forms/react-form-renderer';
3+
import { layoutMapper, formFieldsMapper } from '@data-driven-forms/pf4-component-mapper';
4+
import { Title } from '@patternfly/react-core';
5+
6+
const schema = {
7+
fields: [{
8+
component: componentTypes.TEXT_FIELD,
9+
name: 'field-with-initial-value',
10+
label: 'Will be set to null when you delete value from input',
11+
}, {
12+
component: componentTypes.TEXT_FIELD,
13+
name: 'field-withouth-initial-value',
14+
label: 'Value will be undefined when field is empty',
15+
}],
16+
};
17+
18+
const DataTypesExample = () => {
19+
const [ values, setValues ] = useState({});
20+
return (
21+
<div className="pf4">
22+
<FormRenderer
23+
initialValues={{
24+
'field-with-initial-value': 'Delete me!',
25+
}}
26+
deletedValue={ null }
27+
layoutMapper={ layoutMapper }
28+
formFieldsMapper={ formFieldsMapper }
29+
schema={ schema }
30+
onSubmit={ console.log }
31+
onStateUpdate={ ({ values }) => setValues(values) }
32+
/>
33+
<div style={{ marginTop: 16 }}>
34+
<Title size="md">Form values</Title>
35+
<pre>
36+
{ JSON.stringify(values, null, 2) }
37+
</pre>
38+
</div>
39+
</div>
40+
);};
41+
42+
export default DataTypesExample;

0 commit comments

Comments
 (0)