From a6dcc18db566c287764e9ba1eed40e05fbe84960 Mon Sep 17 00:00:00 2001 From: Janry Date: Tue, 10 Dec 2019 16:02:02 +0800 Subject: [PATCH] fix(@uform/core): fix init visible can not remove value (#492) * refactor(@uform/core): update onFormSubmit position * fix(@uform/antd/next): fix submit cannot autosubmit * fix(@uform/core): fix init visible can not remove value --- packages/core/src/index.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 019bb6068f9..2743c3d40cb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -179,7 +179,7 @@ export function createForm( const mountedChanged = field.isDirty('mounted') const initializedChanged = field.isDirty('initialized') const warningsChanged = field.isDirty('warnings') - const errorsChanges = field.isDirty('errors') + const errorsChanged = field.isDirty('errors') const userUpdateFieldPath = env.userUpdateFields[env.userUpdateFields.length - 1] if (initializedChanged) { @@ -194,6 +194,16 @@ export function createForm( }, true) } } + if (valueChanged) { + userUpdating(field, () => { + setFormValuesIn(path, published.value) + }) + heart.publish(LifeCycleTypes.ON_FIELD_VALUE_CHANGE, field) + } + if (initialValueChanged) { + setFormInitialValuesIn(path, published.initialValue) + heart.publish(LifeCycleTypes.ON_FIELD_INITIAL_VALUE_CHANGE, field) + } if (displayChanged || visibleChanged) { if (visibleChanged) { if (!published.visible) { @@ -228,18 +238,8 @@ export function createForm( if (mountedChanged && published.mounted) { heart.publish(LifeCycleTypes.ON_FIELD_MOUNT, field) } - if (valueChanged) { - userUpdating(field, () => { - setFormValuesIn(path, published.value) - }) - heart.publish(LifeCycleTypes.ON_FIELD_VALUE_CHANGE, field) - } - if (initialValueChanged) { - setFormInitialValuesIn(path, published.initialValue) - heart.publish(LifeCycleTypes.ON_FIELD_INITIAL_VALUE_CHANGE, field) - } - if (errorsChanges) { + if (errorsChanged) { syncFormMessages('errors', published.name, published.errors) } @@ -703,7 +703,10 @@ export function createForm( return arr }, validate(opts?: IFormExtendedValidateFieldOptions) { - return validate(field.getSourceState(state => state.path), opts) + return validate( + field.getSourceState(state => state.path), + opts + ) } } }