File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ import { ButtonProps } from 'antd/lib/button'
4
4
import { useForm , observer } from '@formily/react'
5
5
6
6
export interface ISubmitProps extends ButtonProps {
7
+ onClick ?: ( e : React . MouseEvent < Element , MouseEvent > ) => boolean | void
7
8
onSubmit ?: ( values : any ) => Promise < any > | any
9
+ onSubmitSuccess ?: ( payload : any ) => void
8
10
onSubmitFailed ?: ( feedbacks : Formily . Core . Types . IFormFeedback [ ] ) => void
9
11
}
10
12
11
13
export const Submit : React . FC < ISubmitProps > = observer (
12
- ( { onSubmit, onSubmitFailed, ...props } : ISubmitProps ) => {
14
+ ( { onSubmit, onSubmitFailed, onSubmitSuccess , ...props } : ISubmitProps ) => {
13
15
const form = useForm ( )
14
16
return (
15
17
< Button
@@ -19,10 +21,10 @@ export const Submit: React.FC<ISubmitProps> = observer(
19
21
loading = { props . loading !== undefined ? props . loading : form . submitting }
20
22
onClick = { ( e ) => {
21
23
if ( props . onClick ) {
22
- props . onClick ( e )
24
+ if ( props . onClick ( e ) === false ) return
23
25
}
24
26
if ( onSubmit ) {
25
- form . submit ( onSubmit ) . catch ( onSubmitFailed )
27
+ form . submit ( onSubmit ) . then ( onSubmitSuccess ) . catch ( onSubmitFailed )
26
28
}
27
29
} }
28
30
>
You can’t perform that action at this time.
0 commit comments