1- import React , { ReactNode } from 'react'
1+ import React from 'react'
22import classNames from 'classnames'
3- import { Form as TForm , FormProps as TFormProps } from '@tarojs/components'
3+ import { Form as TForm } from '@tarojs/components'
44import { Context } from './context'
55import { SECRET , useForm } from './useform.taro'
66import { ComponentDefaults } from '@/utils/typings'
77import Cell from '@/packages/cell/index.taro'
8- import { FormInstance } from '@/packages/form/types'
9-
10- export interface FormProps extends TFormProps {
11- footer : ReactNode
12- initialValues : any
13- name : string
14- form : any
15- disabled : boolean
16- divider : boolean
17- validateTrigger : string | string [ ] | false
18- labelPosition : 'top' | 'left' | 'right'
19- starPosition : 'left' | 'right'
20- onFinish : ( values : any ) => void
21- onFinishFailed : ( values : any , errorFields : any ) => void
22- }
8+ import { TaroFormProps , FormInstance } from '@/types'
239
2410const defaultProps = {
2511 ...ComponentDefaults ,
@@ -28,17 +14,19 @@ const defaultProps = {
2814 disabled : false ,
2915 divider : false ,
3016 validateTrigger : 'onChange' ,
17+ onReset : ( ) => { } ,
18+ onSubmit : ( ) => { } ,
3119 onFinish : ( values ) => { } ,
3220 onFinishFailed : ( values , errorFields ) => { } ,
33- } as FormProps
21+ } as TaroFormProps
3422
3523const PositionInfo : any = {
3624 top : 'form-layout-top' ,
3725 left : 'form-layout-left' ,
3826 right : 'form-layout-right' ,
3927}
4028
41- export const Form = React . forwardRef < FormInstance , Partial < FormProps > > (
29+ export const Form = React . forwardRef < FormInstance , Partial < TaroFormProps > > (
4230 ( props , ref ) => {
4331 const classPrefix = 'nut-form'
4432 const {
@@ -54,6 +42,8 @@ export const Form = React.forwardRef<FormInstance, Partial<FormProps>>(
5442 validateTrigger,
5543 labelPosition,
5644 starPosition,
45+ onReset,
46+ onSubmit,
5747 form,
5848 ...rest
5949 } = {
@@ -97,11 +87,13 @@ export const Form = React.forwardRef<FormInstance, Partial<FormProps>>(
9787 e . preventDefault ( )
9888 e . stopPropagation ( )
9989 submit ( )
90+ onSubmit ?.( )
10091 } }
10192 onReset = { ( e ) => {
10293 e . preventDefault ( )
10394 e . stopPropagation ( )
10495 resetFields ( )
96+ onReset ?.( )
10597 } }
10698 >
10799 < Cell . Group divider = { divider } >
0 commit comments