form icon indicating copy to clipboard operation
form copied to clipboard

Default value on field is overwriting default value on useAppForm

Open MylesWardell opened this issue 7 months ago • 2 comments

Describe the bug

As mentioned in the title if you have a default value on a form.AppField this overwites the value coming from useAppForm for async loading. Hierarchically these should be overwritten from parent.

Prio

  1. useAppForm defaultValue
  2. formOptions defaultValue
  3. form.AppField defaultValue

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/frosty-james-mwktlf

Steps to reproduce

  1. Create a useAppForm with defaultValue
  2. Declare an empty string or countryCode for a field as default value if no value exists
  3. Have defaultValue from base
  4. Expect defaultValue change on root to overwrite fieldDefaultValue

Expected behavior

Expect defaultValue change on root to overwrite fieldDefaultValue

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Windows Chrome 136.0.7103.114

TanStack Form adapter

None

TanStack Form version

^1.11.1

TypeScript version

^5.8.3

Additional context

No response

MylesWardell avatar May 30 '25 02:05 MylesWardell

The field is more specific. Can you elaborate on why the form should take priority?

LeCarbonator avatar May 30 '25 11:05 LeCarbonator

In my use case the source of truth comes from the server so any default values (like a default countryCode on a country code dropdown) does not change the default value.

How can i have field specific default values and have a default value set via the form? My fields are generic using the composition useAppForm and I would like a defaultValue on countryCode.

To return the question when would you want a form controller to not overwrite the default value of the field? Whats the use case here?

More generically when does a child ever overwrite the parent state?

MylesWardell avatar Jun 02 '25 01:06 MylesWardell