@@ -23,7 +23,7 @@ const schema = {
23
23
} ;
24
24
25
25
const FormTemplate = ( { formFields, schema } ) => {
26
- const { handleSubmit, reset , getState } = useFormApi ( ) ;
26
+ const { handleSubmit, onReset , onCancel , getState, reset } = useFormApi ( ) ;
27
27
const { submitting, valid, pristine } = getState ( ) ;
28
28
29
29
return (
@@ -36,22 +36,32 @@ const FormTemplate = ({ formFields, schema }) => {
36
36
< Button disabled = { submitting || ! valid } style = { { marginRight : 8 } } type = "submit" color = "primary" variant = "contained" >
37
37
Submit
38
38
</ Button >
39
- < Button disabled = { pristine } style = { { marginRight : 8 } } onClick = { reset } variant = "contained" >
39
+ < Button disabled = { pristine } style = { { marginRight : 8 } } onClick = { ( ) => { onReset ( ) ; reset ( ) ; } } variant = "contained" >
40
40
Reset
41
41
</ Button >
42
- < Button variant = "contained" > Cancel</ Button >
42
+ < Button variant = "contained" onClick = { onCancel } > Cancel</ Button >
43
43
</ div >
44
44
) }
45
45
</ FormSpy >
46
46
</ Form >
47
47
) ;
48
48
} ;
49
49
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 ) ) ;
51
54
52
55
const FormControls = ( ) => (
53
56
< 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
+ />
55
65
</ div >
56
66
) ;
57
67
0 commit comments