@@ -34,6 +34,7 @@ import FormItemLabel from './FormItemLabel';
34
34
import FormItemInput from './FormItemInput' ;
35
35
import type { ValidationRule } from './Form' ;
36
36
import { useProvideFormItemContext } from './FormItemContext' ;
37
+ import useDebounce from './utils/useDebounce' ;
37
38
38
39
const ValidateStatuses = tuple ( 'success' , 'warning' , 'error' , 'validating' , '' ) ;
39
40
export type ValidateStatus = typeof ValidateStatuses [ number ] ;
@@ -368,15 +369,24 @@ export default defineComponent({
368
369
onBeforeUnmount ( ( ) => {
369
370
formContext . removeField ( eventKey ) ;
370
371
} ) ;
372
+ const debounceErrors = useDebounce ( errors ) ;
373
+ const mergedValidateStatus = computed ( ( ) => {
374
+ if ( props . validateStatus !== undefined ) {
375
+ return props . validateStatus ;
376
+ } else if ( debounceErrors . value . length ) {
377
+ return 'error' ;
378
+ }
379
+ return validateState . value ;
380
+ } ) ;
371
381
const itemClassName = computed ( ( ) => ( {
372
382
[ `${ prefixCls . value } -item` ] : true ,
373
383
374
384
// Status
375
- [ `${ prefixCls . value } -item-has-feedback` ] : validateState . value && props . hasFeedback ,
376
- [ `${ prefixCls . value } -item-has-success` ] : validateState . value === 'success' ,
377
- [ `${ prefixCls . value } -item-has-warning` ] : validateState . value === 'warning' ,
378
- [ `${ prefixCls . value } -item-has-error` ] : validateState . value === 'error' ,
379
- [ `${ prefixCls . value } -item-is-validating` ] : validateState . value === 'validating' ,
385
+ [ `${ prefixCls . value } -item-has-feedback` ] : mergedValidateStatus . value && props . hasFeedback ,
386
+ [ `${ prefixCls . value } -item-has-success` ] : mergedValidateStatus . value === 'success' ,
387
+ [ `${ prefixCls . value } -item-has-warning` ] : mergedValidateStatus . value === 'warning' ,
388
+ [ `${ prefixCls . value } -item-has-error` ] : mergedValidateStatus . value === 'error' ,
389
+ [ `${ prefixCls . value } -item-is-validating` ] : mergedValidateStatus . value === 'validating' ,
380
390
[ `${ prefixCls . value } -item-hidden` ] : props . hidden ,
381
391
} ) ) ;
382
392
return ( ) => {
@@ -387,7 +397,7 @@ export default defineComponent({
387
397
{ ...attrs }
388
398
class = { [
389
399
itemClassName . value ,
390
- ( help !== undefined && help !== null ) || errors . value . length
400
+ ( help !== undefined && help !== null ) || debounceErrors . value . length
391
401
? `${ prefixCls . value } -item-with-help`
392
402
: '' ,
393
403
attrs . class ,
@@ -409,10 +419,11 @@ export default defineComponent({
409
419
{ /* Input Group */ }
410
420
< FormItemInput
411
421
{ ...props }
412
- errors = { help !== undefined && help !== null ? toArray ( help ) : errors . value }
422
+ errors = {
423
+ help !== undefined && help !== null ? toArray ( help ) : debounceErrors . value
424
+ }
413
425
prefixCls = { prefixCls . value }
414
- status = { validateState . value }
415
- validateStatus = { validateState . value }
426
+ status = { mergedValidateStatus . value }
416
427
ref = { inputRef }
417
428
help = { help }
418
429
extra = { props . extra ?? slots . extra ?.( ) }
0 commit comments