Skip to content

Commit

Permalink
fix: unmount field now updates form
Browse files Browse the repository at this point in the history
* Add basic tests for arrays

* Ran prettier

* Ran prettier

* Add new test for bug

* Fix bug regarding preserved values even if field is umounted

* Run prettier
  • Loading branch information
Christian24 authored Nov 3, 2023
1 parent 6658947 commit 25a2fc8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class FieldApi<
unsubscribe()
if (!preserveValue) {
delete info.instances[this.uid]
this.form.deleteField(this.name)
}

if (!Object.keys(info.instances).length && !preserveValue) {
Expand Down
4 changes: 4 additions & 0 deletions packages/form-core/src/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,5 +601,9 @@ describe('field api', () => {
const info = form.getFieldInfo(field.name)
expect(info.instances[field.uid]).toBeUndefined()
expect(Object.keys(info.instances).length).toBe(0)

// Field should have been removed from the form as well
expect(form.state.values.name).toBeUndefined()
expect(form.state.fieldMeta.name).toBeUndefined()
})
})

0 comments on commit 25a2fc8

Please sign in to comment.