Skip to content

Commit

Permalink
fix: duplicate triggering of the click event (#29)
Browse files Browse the repository at this point in the history
* fix(reset): duplicate triggering of the click event

* fix(submit): duplicate triggering of the click event
  • Loading branch information
Sun79 authored Apr 18, 2024
1 parent cad9c09 commit d7f7505
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/components/src/reset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { observer } from '@formily/reactive-vue'
import { useParentForm } from '@formily/vue'
import { Button } from 'ant-design-vue'
import { defineComponent } from 'vue'
import { defineComponent, type PropType } from 'vue'

export const Reset = observer(
defineComponent({
Expand All @@ -14,7 +14,8 @@ export const Reset = observer(
validate: {
type: Boolean,
default: false
}
},
onClick: Function as PropType<(event: MouseEvent) => void | boolean>
},
emits: ['resetValidateSuccess', 'resetValidateFailed'],
setup(props, { attrs, slots, emit }) {
Expand All @@ -25,7 +26,7 @@ export const Reset = observer(
<Button
{...attrs}
onClick={async (e) => {
const result = await (attrs as any).onClick?.(e)
const result = await props.onClick?.(e)
if (result === false) return
form
?.reset('*', {
Expand Down
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 d7f7505

Please sign in to comment.