FormApi.reset seems to break a form
Describe the bug
Hi,
I am currently working on a prototype Lit wrapper for Tanstack Form. My prototype shows problems with FormApi.reset(). This is the initial state of the form:
{
"values": {},
"fieldMeta": {
"firstName": {
"isValidating": false,
"isTouched": false,
"touchedErrors": [],
"errors": [],
"errorMap": {}
},
"lastName": {
"isValidating": false,
"isTouched": false,
"touchedErrors": [],
"errors": [],
"errorMap": {}
},
"color": {
"isValidating": false,
"isTouched": false,
"touchedErrors": [],
"errors": [],
"errorMap": {}
},
"employed": {
"isValidating": false,
"isTouched": false,
"touchedErrors": [],
"errors": [],
"errorMap": {}
}
},
"canSubmit": true,
"isFieldsValid": true,
"isFieldsValidating": false,
"isFormValid": true,
"isFormValidating": false,
"isSubmitted": false,
"isSubmitting": false,
"isTouched": false,
"isValid": true,
"isValidating": false,
"submissionAttempts": 0,
"formValidationCount": 0
}
After calling FormApi.reset() the state is:
{
"values": {},
"fieldMeta": {},
"canSubmit": true,
"isFieldsValid": true,
"isFieldsValidating": false,
"isFormValid": true,
"isFormValidating": false,
"isSubmitted": false,
"isSubmitting": false,
"isTouched": false,
"isValid": true,
"isValidating": false,
"submissionAttempts": 0,
"formValidationCount": 0
}
Whenever a field changes Tanstack form then crashes at: https://github.com/TanStack/form/blob/84e257f310ab1eedb4cc185199c0a41e4f701144/packages/form-core/src/FieldApi.ts#L201. This happens because errorMap is undefined.
Your minimal, reproducible example
https://stackblitz.com/github/christian24/tanstack-form-lit-prototype?file=src%2Findex.ts
Steps to reproduce
- Click on reset
- Change a field
Error appears in console.
Expected behavior
I expect reset to not break the form.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- Mac OS
- Edge
- latest
Tanstack Form adapter
None
TanStack Form version
0.61.0
TypeScript version
^5.0.2
Additional context
FYI @crutchcorn :)
@crutchcorn can you assign this to me please
Has anyone found the outcome of this bug? Or Has it being resolved?
I think @vikaskumar89 is working on fixing it.
any updates?
Hi, I am not working on this any longer. Feel free to pick this up.
On Tue, Feb 27, 2024, 21:11 barsikus007 @.***> wrote:
any updates?
— Reply to this email directly, view it on GitHub https://github.com/TanStack/form/issues/495#issuecomment-1967595667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD6VM2ZBUEH75FNKGUNCXI3YVZDXPAVCNFSM6AAAAAA6WPNZROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRXGU4TKNRWG4 . You are receiving this because you were mentioned.Message ID: @.***>
any workaround?
This should be fixed in the latest version