@@ -260,9 +260,16 @@ export function createForm<FieldProps, VirtualFieldProps>(
260
260
const isEmptyInitialValue = ! isValid ( published . initialValue )
261
261
if ( isEmptyValue || isEmptyInitialValue ) {
262
262
field . setSourceState ( ( state : IFieldState < FieldProps > ) => {
263
- if ( isEmptyValue ) state . value = getFormValuesIn ( state . name )
264
- if ( isEmptyInitialValue )
265
- state . initialValue = getFormInitialValuesIn ( state . name )
263
+ if ( isEmptyValue ) {
264
+ const formValue = getFormValuesIn ( state . name )
265
+ state . value = isValid ( formValue ) ? formValue : state . value
266
+ }
267
+ if ( isEmptyInitialValue ) {
268
+ const formInitialValue = getFormInitialValuesIn ( state . name )
269
+ state . initialValue = isValid ( formInitialValue )
270
+ ? formInitialValue
271
+ : state . initialValue
272
+ }
266
273
} )
267
274
}
268
275
}
@@ -472,6 +479,7 @@ export function createForm<FieldProps, VirtualFieldProps>(
472
479
computeState,
473
480
dataType,
474
481
useDirty,
482
+ unmountRemoveValue,
475
483
props
476
484
} : Exclude < IFieldStateProps , 'dataPath' | 'nodePath' > ) : IField {
477
485
let field : IField
@@ -486,6 +494,7 @@ export function createForm<FieldProps, VirtualFieldProps>(
486
494
dataPath,
487
495
computeState,
488
496
dataType,
497
+ unmountRemoveValue,
489
498
useDirty : isValid ( useDirty ) ? useDirty : options . useDirty
490
499
} )
491
500
field . subscription = {
@@ -508,7 +517,9 @@ export function createForm<FieldProps, VirtualFieldProps>(
508
517
// initialValue > formInitialValue
509
518
state . initialValue = isValid ( initialValue )
510
519
? initialValue
511
- : formInitialValue
520
+ : isValid ( formInitialValue )
521
+ ? formInitialValue
522
+ : initialValue
512
523
if ( isValid ( visible ) ) {
513
524
state . visible = visible
514
525
}
@@ -1014,7 +1025,7 @@ export function createForm<FieldProps, VirtualFieldProps>(
1014
1025
env . submittingTask = async ( ) => {
1015
1026
// 增加onFormSubmitValidateStart来明确submit引起的校验开始了
1016
1027
heart . publish ( LifeCycleTypes . ON_FORM_SUBMIT_VALIDATE_START , state )
1017
- await validate ( '' , { throwErrors : false } )
1028
+ await validate ( '' , { throwErrors : false , hostRendering : true } )
1018
1029
const validated : IFormValidateResult = state . getState ( state => ( {
1019
1030
errors : state . errors ,
1020
1031
warnings : state . warnings
@@ -1074,7 +1085,7 @@ export function createForm<FieldProps, VirtualFieldProps>(
1074
1085
path ?: FormPathPattern ,
1075
1086
opts ?: IFormExtendedValidateFieldOptions
1076
1087
) : Promise < IFormValidateResult > {
1077
- const { throwErrors = true } = opts || { }
1088
+ const { throwErrors = true , hostRendering } = opts || { }
1078
1089
if ( ! state . getState ( state => state . validating ) ) {
1079
1090
state . setSourceState ( state => {
1080
1091
state . validating = true
@@ -1087,14 +1098,14 @@ export function createForm<FieldProps, VirtualFieldProps>(
1087
1098
}
1088
1099
1089
1100
heart . publish ( LifeCycleTypes . ON_FORM_VALIDATE_START , state )
1090
- if ( graph . size > 100 ) env . hostRendering = true
1101
+ if ( graph . size > 100 && hostRendering ) env . hostRendering = true
1091
1102
const payload = await validator . validate ( path , opts )
1092
1103
clearTimeout ( env . validateTimer )
1093
1104
state . setState ( state => {
1094
1105
state . validating = false
1095
1106
} )
1096
1107
heart . publish ( LifeCycleTypes . ON_FORM_VALIDATE_END , state )
1097
- if ( graph . size > 100 ) {
1108
+ if ( graph . size > 100 && hostRendering ) {
1098
1109
heart . publish ( LifeCycleTypes . ON_FORM_HOST_RENDER , state )
1099
1110
env . hostRendering = false
1100
1111
}
0 commit comments