Skip to content

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

Open

Description

@JohnnyOu

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions