Skip to content
Source
Sign inSign up
TanStack/form

form.resetField does not reset to default value when default value is undefined #2424

OpenJohnnyOu(GitHub profile, opens in a new tab) opened this issue 0 comments

Describe the bug

In a form whose schema has optional fields, after calling form.resetField function on an optional field whose default value is undefined, the current value is still present and is not undefined as expected.

The same function works for fields that have defined default values, i.e. resetField turns the current value to the defined default value.

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/gfsmpw

Steps to reproduce

  1. Visit the linked code sandbox
  2. In the rendered sandbox webpage, note that the default value of foo (the field in question) is undefined
  3. Begin typing any string in input box, observing that the string is reflected below, next to Current value of 'foo'
  4. Click on button to reset, noting that the user input string is still shown next to Current value of 'foo'

Expected behavior

When form.resetField is called, that field's value should become identical to the default value, including undefined, and field meta such as isDefaultValue should be true.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 1.33.5

TanStack Form adapter

react-form

TanStack Form version

v1.33.5

TypeScript version

v5.9.3

Additional context

No response

Sign in to join this conversation.