TanStack / form

🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
https://tanstack.com/form
MIT License
3.74k stars 338 forks source link

FormApi.reset seems to break a form #495

Closed Christian24 closed 6 months ago

Christian24 commented 12 months ago

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

  1. Click on reset
  2. 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

Tanstack Form adapter

None

TanStack Form version

0.61.0

TypeScript version

^5.0.2

Additional context

FYI @crutchcorn :)

vikaskumar89 commented 12 months ago

@crutchcorn can you assign this to me please

MiirzaBaig commented 11 months ago

Has anyone found the outcome of this bug? Or Has it being resolved?

Christian24 commented 11 months ago

I think @vikaskumar89 is working on fixing it.

barsikus007 commented 8 months ago

any updates?

vikaskumar89 commented 8 months ago

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: @.***>

masylum commented 7 months ago

any workaround?

crutchcorn commented 6 months ago

This should be fixed in the latest version