Skip to content

Commit

Permalink
fix(submit): duplicate triggering of the click event
Browse files Browse the repository at this point in the history
  • Loading branch information
Sun79 committed Jan 9, 2024
1 parent e2f51b3 commit 8edc71c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/components/src/submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { observer } from '@formily/reactive-vue'
import { useParentForm } from '@formily/vue'
import type { ButtonProps } from 'ant-design-vue'
import { Button } from 'ant-design-vue'
import { defineComponent } from 'vue'
import { defineComponent, type PropType } from 'vue'

import type { IFormFeedback } from '@formily/core'

export interface ISubmitProps extends ButtonProps {
onClick?: (e: MouseEvent) => any
onClick?: (event: MouseEvent) => void | boolean
onSubmit?: (values: any) => any
onSubmitSuccess?: (payload: any) => void
onSubmitFailed?: (feedbacks: IFormFeedback[]) => void
Expand All @@ -16,19 +16,22 @@ export interface ISubmitProps extends ButtonProps {
export const Submit = observer(
defineComponent({
name: 'FSubmit',
props: {
onClick: Function as PropType<ISubmitProps['onClick']>
},
setup(props, { attrs, slots }) {
const formRef = useParentForm()

return () => {
const { onClick, onSubmit, onSubmitSuccess, onSubmitFailed } = attrs
const { onSubmit, onSubmitSuccess, onSubmitFailed } = attrs
const form = formRef?.value
return (
<Button
type="primary"
{...attrs}
loading={attrs.loading !== undefined ? attrs.loading : form?.submitting}
onClick={async (e) => {
const result = await (onClick as Function)?.(e)
const result = await props.onClick?.(e)
if (result === false) return
if (onSubmit) {
form
Expand Down

0 comments on commit 8edc71c

Please sign in to comment.