Skip to content

Commit

Permalink
feat(antd): improve Submit API (#1640)
Browse files Browse the repository at this point in the history
  • Loading branch information
li9269391 authored Jun 24, 2021
1 parent 580570b commit 6b33ec9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/antd/src/submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { ButtonProps } from 'antd/lib/button'
import { useForm, observer } from '@formily/react'

export interface ISubmitProps extends ButtonProps {
onClick?: (e: React.MouseEvent<Element, MouseEvent>) => boolean | void
onSubmit?: (values: any) => Promise<any> | any
onSubmitSuccess?: (payload: any) => void
onSubmitFailed?: (feedbacks: Formily.Core.Types.IFormFeedback[]) => void
}

export const Submit: React.FC<ISubmitProps> = observer(
({ onSubmit, onSubmitFailed, ...props }: ISubmitProps) => {
({ onSubmit, onSubmitFailed, onSubmitSuccess, ...props }: ISubmitProps) => {
const form = useForm()
return (
<Button
Expand All @@ -19,10 +21,10 @@ export const Submit: React.FC<ISubmitProps> = observer(
loading={props.loading !== undefined ? props.loading : form.submitting}
onClick={(e) => {
if (props.onClick) {
props.onClick(e)
if (props.onClick(e) === false) return
}
if (onSubmit) {
form.submit(onSubmit).catch(onSubmitFailed)
form.submit(onSubmit).then(onSubmitSuccess).catch(onSubmitFailed)
}
}}
>
Expand Down

0 comments on commit 6b33ec9

Please sign in to comment.