Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix field destroyed still can be assigned value #3115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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