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#
- Visit the linked code sandbox
- In the rendered sandbox webpage, note that the default value of
foo (the field in question) is undefined
- Begin typing any string in input box, observing that the string is reflected below, next to
Current value of 'foo'
- 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