diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts index 5fbca705106..3b1cb8ce0cb 100644 --- a/packages/core/src/internals.ts +++ b/packages/core/src/internals.ts @@ -206,7 +206,7 @@ export const createFormInternals = (options: IFormCreatorOptions = {}) => { unmounted === true || display === false ) { - form.setSourceState(state => { + form.setState(state => { state.errors = state.errors || [] state.warnings = state.warnings || [] state.errors = state.errors.reduce((buf: any, item: any) => { @@ -237,7 +237,7 @@ export const createFormInternals = (options: IFormCreatorOptions = {}) => { function syncFormMessages(type: string, fieldState: IFieldState) { const { name, path } = fieldState const messages = fieldState[type] - form.setSourceState(state => { + form.setState(state => { let foundField = false state[type] = state[type] || [] state[type] = state[type].reduce((buf: any, item: any) => { diff --git a/packages/core/src/shared/model.ts b/packages/core/src/shared/model.ts index dc40c3baa82..ecf7fa0dfc8 100644 --- a/packages/core/src/shared/model.ts +++ b/packages/core/src/shared/model.ts @@ -5,7 +5,8 @@ import { FormPath, FormPathPattern, defaults, - shallowClone + shallowClone, + isStr } from '@formily/shared' import { produce, enableAllPlugins, setAutoFreeze, Draft } from 'immer' import { StateDirtyMap, IDirtyModelFactory, NormalRecord } from '../types' @@ -225,13 +226,20 @@ export const createModel = < } } - hasChanged = (path?: FormPathPattern) => { - return path - ? !isEqual( + hasChanged = (pattern?: FormPathPattern) => { + if (!pattern) { + return this.dirtyCount > 0 + } else { + const path = FormPath.parse(pattern) + if (path.length > 1 || !isStr(pattern)) { + return !isEqual( FormPath.getIn(this.prevState, path), FormPath.getIn(this.state, path) ) - : !isEqual(this.prevState, this.state) + } else { + return this.dirtys[pattern] + } + } } } }