Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(antd): improve Submit API #1640

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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