1
1
import type { Ref } from 'vue' ;
2
- import { reactive , watch , nextTick , unref , shallowRef } from 'vue' ;
2
+ import { reactive , watch , nextTick , unref , shallowRef , toRaw } from 'vue' ;
3
3
import cloneDeep from 'lodash-es/cloneDeep' ;
4
4
import intersection from 'lodash-es/intersection' ;
5
5
import isEqual from 'lodash-es/isEqual' ;
@@ -8,7 +8,7 @@ import omit from 'lodash-es/omit';
8
8
import { validateRules } from './utils/validateUtil' ;
9
9
import { defaultValidateMessages } from './utils/messages' ;
10
10
import { allPromiseFinish } from './utils/asyncUtil' ;
11
- import type { RuleError , ValidateMessages } from './interface' ;
11
+ import type { Callbacks , RuleError , ValidateMessages } from './interface' ;
12
12
import type { ValidateStatus } from './FormItem' ;
13
13
14
14
interface DebounceSettings {
@@ -98,6 +98,7 @@ function useForm(
98
98
deep ?: boolean ;
99
99
validateOnRuleChange ?: boolean ;
100
100
debounce ?: DebounceSettings ;
101
+ onValidate ?: Callbacks [ 'onValidate' ] ;
101
102
} ,
102
103
) : {
103
104
modelRef : Props | Ref < Props > ;
@@ -252,6 +253,11 @@ function useForm(
252
253
const res = results . filter ( result => result && result . errors . length ) ;
253
254
validateInfos [ name ] . validateStatus = res . length ? 'error' : 'success' ;
254
255
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
+ ) ;
255
261
}
256
262
} ) ;
257
263
return promise ;
0 commit comments