Skip to content

Commit

Permalink
fix(core): fix field destroyed still can be assigned value (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored May 11, 2022
1 parent 7d731af commit 5dd9acc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/core/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,3 +2207,17 @@ test('conflict name for errors filter', async () => {
await aa1.onInput('')
expect(aa.invalid).toBe(false)
})

test('field destroyed can not be assign value', () => {
const form = attach(createForm<any>())
const aa = attach(
form.createField({
name: 'aa',
})
)
aa.destroy()
aa.initialValue = 222
aa.value = 111
expect(form.values).toEqual({})
expect(form.initialValues).toEqual({})
})
2 changes: 2 additions & 0 deletions packages/core/src/models/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export class Field<
}

set value(value: ValueType) {
if (this.destroyed) return
if (!this.initialized) {
if (this.display === 'none') {
this.caches.value = value
Expand All @@ -364,6 +365,7 @@ export class Field<
}

set initialValue(initialValue: ValueType) {
if (this.destroyed) return
if (!this.initialized) {
if (
!allowAssignDefaultValue(this.initialValue, initialValue) &&
Expand Down

0 comments on commit 5dd9acc

Please sign in to comment.