11import type { Ref } from 'vue' ;
2- import { reactive , watch , nextTick , unref , shallowRef } from 'vue' ;
2+ import { reactive , watch , nextTick , unref , shallowRef , toRaw } from 'vue' ;
33import cloneDeep from 'lodash-es/cloneDeep' ;
44import intersection from 'lodash-es/intersection' ;
55import isEqual from 'lodash-es/isEqual' ;
@@ -8,7 +8,7 @@ import omit from 'lodash-es/omit';
88import { validateRules } from './utils/validateUtil' ;
99import { defaultValidateMessages } from './utils/messages' ;
1010import { allPromiseFinish } from './utils/asyncUtil' ;
11- import type { RuleError , ValidateMessages } from './interface' ;
11+ import type { Callbacks , RuleError , ValidateMessages } from './interface' ;
1212import type { ValidateStatus } from './FormItem' ;
1313
1414interface DebounceSettings {
@@ -98,6 +98,7 @@ function useForm(
9898 deep ?: boolean ;
9999 validateOnRuleChange ?: boolean ;
100100 debounce ?: DebounceSettings ;
101+ onValidate ?: Callbacks [ 'onValidate' ] ;
101102 } ,
102103) : {
103104 modelRef : Props | Ref < Props > ;
@@ -252,6 +253,11 @@ function useForm(
252253 const res = results . filter ( result => result && result . errors . length ) ;
253254 validateInfos [ name ] . validateStatus = res . length ? 'error' : 'success' ;
254255 validateInfos [ name ] . help = res . length ? res . map ( r => r . errors ) : '' ;
256+ options ?. onValidate ?.(
257+ name ,
258+ ! res . length ,
259+ res . length ? toRaw ( validateInfos [ name ] . help [ 0 ] ) : null ,
260+ ) ;
255261 }
256262 } ) ;
257263 return promise ;
0 commit comments