Skip to content

Commit 45ff1cc

Browse files
committed
Fix initiliazeOnMount demo
1 parent 11e44dd commit 45ff1cc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

packages/react-renderer-demo/src/app/src/doc-components/initialize-mount.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useState } from 'react';
22
import FormRenderer from '@data-driven-forms/react-form-renderer/dist/cjs/form-renderer';
3+
import useFormApi from '@data-driven-forms/react-form-renderer/dist/cjs/use-form-api';
34
import componentTypes from '@data-driven-forms/react-form-renderer/dist/cjs/component-types';
45
import FormTemplate from '@data-driven-forms/pf4-component-mapper/dist/cjs/form-template';
56
import TextField from '@data-driven-forms/pf4-component-mapper/dist/cjs/text-field';
@@ -10,14 +11,20 @@ import { Title } from '@patternfly/react-core/dist/js/components/Title/Title';
1011
const componentMapper = {
1112
[componentTypes.TEXT_FIELD]: TextField,
1213
[componentTypes.WIZARD]: Wizard,
13-
[componentTypes.SELECT]: Select
14+
[componentTypes.SELECT]: Select,
15+
Summary: () => {
16+
const { getState } = useFormApi();
17+
18+
return <Title size="md">{getState().values['chosen-way']}</Title>;
19+
}
1420
};
1521

1622
const schema = {
1723
fields: [
1824
{
1925
component: componentTypes.WIZARD,
2026
name: 'wizard',
27+
crossroads: ['selection'],
2128
fields: [
2229
{
2330
title: 'Choose your way',
@@ -50,6 +57,10 @@ const schema = {
5057
hideField: true,
5158
name: 'chosen-way',
5259
initialValue: 'User chose the first way'
60+
},
61+
{
62+
component: 'Summary',
63+
name: 'summary'
5364
}
5465
]
5566
},
@@ -63,6 +74,10 @@ const schema = {
6374
hideField: true,
6475
name: 'chosen-way',
6576
initialValue: 'User chose the second way'
77+
},
78+
{
79+
component: 'Summary',
80+
name: 'summary'
6681
}
6782
]
6883
}
@@ -71,22 +86,23 @@ const schema = {
7186
]
7287
};
7388

89+
const FormTemplateWrapper = (props) => <FormTemplate {...props} showFormControls={false} />;
90+
7491
const InitializeOnMountWizardExample = () => {
7592
const [values, setValues] = useState({});
7693
return (
7794
<div className="pf4">
95+
<div style={{ marginTop: 16, marginBottom: 16 }}>
96+
<Title size="md">Form values</Title>
97+
<pre>{JSON.stringify(values, null, 2)}</pre>
98+
</div>
7899
<FormRenderer
79-
FormTemplate={(props) => <FormTemplate {...props} showFormControls={false} />}
100+
FormTemplate={FormTemplateWrapper}
80101
componentMapper={componentMapper}
81102
schema={schema}
82103
onSubmit={console.log}
83104
debug={({ values }) => setValues(values)}
84-
showFormControls={false}
85105
/>
86-
<div style={{ marginTop: 16 }}>
87-
<Title size="md">Form values</Title>
88-
<pre>{JSON.stringify(values, null, 2)}</pre>
89-
</div>
90106
</div>
91107
);
92108
};

0 commit comments

Comments
 (0)