TanStack / form

🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.

Home Page:https://tanstack.com/form

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FormApi.reset seems to break a form

Christian24 opened this issue · comments

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:

state.meta.errors = Object.values(state.meta.errorMap).filter(
. 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

  • 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.