form icon indicating copy to clipboard operation
form copied to clipboard

FormApi.reset seems to break a form

Open Christian24 opened this issue 2 years ago • 3 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: 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

  • Mac OS
  • Edge
  • latest

Tanstack Form adapter

None

TanStack Form version

0.61.0

TypeScript version

^5.0.2

Additional context

FYI @crutchcorn :)

Christian24 avatar Oct 30 '23 18:10 Christian24

@crutchcorn can you assign this to me please

vikaskumar89 avatar Oct 31 '23 06:10 vikaskumar89

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

MiirzaBaig avatar Nov 04 '23 10:11 MiirzaBaig

I think @vikaskumar89 is working on fixing it.

Christian24 avatar Nov 04 '23 10:11 Christian24

any updates?

barsikus007 avatar Feb 27 '24 21:02 barsikus007

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

vikaskumar89 avatar Feb 28 '24 08:02 vikaskumar89

any workaround?

masylum avatar Mar 11 '24 23:03 masylum

This should be fixed in the latest version

crutchcorn avatar Apr 16 '24 16:04 crutchcorn