@@ -270,6 +270,7 @@ private bool TryGetValidator(Type modelType, string fieldName, out IValidateComp
270270 /// <param name="results"></param>
271271 internal async Task ValidateObject ( ValidationContext context , List < ValidationResult > results )
272272 {
273+ _tcs = new TaskCompletionSource < bool > ( ) ;
273274 _validateResults . Clear ( ) ;
274275
275276 if ( ValidateAllProperties )
@@ -343,14 +344,9 @@ internal async Task ValidateObject(ValidationContext context, List<ValidationRes
343344 {
344345 await validator . ToggleMessage ( messages ) ;
345346 }
346-
347- // 确保 _invalid 在没有验证组件时被正确设置
348- // Ensure _invalid is properly set when there are no validation components
349- if ( _validatorCache . IsEmpty )
350- {
351- _invalid = results . Count > 0 ;
352- }
353347 }
348+
349+ _tcs . TrySetResult ( results . Count == 0 ) ;
354350 }
355351
356352 /// <summary>
@@ -539,19 +535,14 @@ private async Task ValidateAsync(IValidateComponent validator, ValidationContext
539535 }
540536 ValidateDataAnnotations ( propertyValue , context , messages , pi ) ;
541537 }
542-
543- _tcs = new TaskCompletionSource < bool > ( ) ;
544- _tcs . TrySetResult ( messages . Count == 0 ) ;
545538 }
546539 else
547540 {
548541 ValidateDataAnnotations ( propertyValue , context , messages , pi ) ;
549542 if ( messages . Count == 0 )
550543 {
551544 // 自定义验证组件
552- _tcs = new TaskCompletionSource < bool > ( ) ;
553545 await validator . ValidatePropertyAsync ( propertyValue , context , messages ) ;
554- _tcs . TrySetResult ( messages . Count == 0 ) ;
555546 }
556547
557548 if ( messages . Count == 0 )
@@ -574,12 +565,8 @@ private async Task ValidateAsync(IValidateComponent validator, ValidationContext
574565 }
575566 }
576567 }
577-
578- _invalid = messages . Count > 0 ;
579568 }
580569
581- private bool _invalid = false ;
582-
583570 private List < ButtonBase > AsyncSubmitButtons { get ; } = [ ] ;
584571
585572 /// <summary>
@@ -665,11 +652,7 @@ private async Task OnInvalidSubmitForm(EditContext context)
665652 /// 验证方法 用于代码调用触发表单验证
666653 /// </summary>
667654 /// <returns></returns>
668- public bool Validate ( )
669- {
670- _invalid = true ;
671- return Validator . Validate ( ) && ! _invalid ;
672- }
655+ public bool Validate ( ) => Validator . Validate ( ) ;
673656
674657 /// <summary>
675658 /// 通知属性改变方法
0 commit comments