Skip to content

Commit 1963077

Browse files
committed
Include example of onCancel onReset in formButtons
1 parent aa50c53 commit 1963077

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/react-renderer-demo/src/app/src/doc-components/custom-buttons.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const schema = {
2323
};
2424

2525
const FormTemplate = ({ formFields, schema }) => {
26-
const { handleSubmit, reset, getState } = useFormApi();
26+
const { handleSubmit, onReset, onCancel, getState, reset } = useFormApi();
2727
const { submitting, valid, pristine } = getState();
2828

2929
return (
@@ -36,22 +36,32 @@ const FormTemplate = ({ formFields, schema }) => {
3636
<Button disabled={submitting || !valid} style={{ marginRight: 8 }} type="submit" color="primary" variant="contained">
3737
Submit
3838
</Button>
39-
<Button disabled={pristine} style={{ marginRight: 8 }} onClick={reset} variant="contained">
39+
<Button disabled={pristine} style={{ marginRight: 8 }} onClick={() => { onReset(); reset(); }} variant="contained">
4040
Reset
4141
</Button>
42-
<Button variant="contained">Cancel</Button>
42+
<Button variant="contained" onClick={onCancel}>Cancel</Button>
4343
</div>
4444
)}
4545
</FormSpy>
4646
</Form>
4747
);
4848
};
4949

50-
const asyncSubmit = (values, api) => new Promise((resolve) => setTimeout(() => resolve('Yay'), 1500));
50+
const asyncSubmit = (values, api) => new Promise((resolve) => setTimeout(() => {
51+
console.log('FormValues', values);
52+
resolve('Yay');
53+
}, 1500));
5154

5255
const FormControls = () => (
5356
<div className="pf4">
54-
<FormRenderer FormTemplate={FormTemplate} componentMapper={componentMapper} schema={schema} onSubmit={asyncSubmit} />
57+
<FormRenderer
58+
FormTemplate={FormTemplate}
59+
componentMapper={componentMapper}
60+
schema={schema}
61+
onSubmit={asyncSubmit}
62+
onCancel={() => console.log('Cancelling')}
63+
onReset={() => console.log('Resetting')}
64+
/>
5565
</div>
5666
);
5767

0 commit comments

Comments
 (0)