-
-
Notifications
You must be signed in to change notification settings - Fork 446
form.resetFieldValue() doesn't work for nested fields #1496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Failing unit test: it('should reset nested fields', () => {
const defaultValues = {
shallow: '',
nested: {
field: {
name: '',
},
},
}
const form = new FormApi({
defaultValues,
})
form.mount()
form.setFieldValue('shallow', 'Shallow')
form.setFieldValue('nested.field.name', 'Nested')
expect(form.state.values.shallow).toEqual('Shallow')
expect(form.state.values.nested.field.name).toEqual('Nested')
form.resetField('shallow')
expect(form.state.values.shallow).toEqual('')
form.resetField('nested.field.name')
expect(form.state.values.nested.field.name).toEqual('')
}) |
LeCarbonator
added a commit
to LeCarbonator/tanstack-form
that referenced
this issue
May 9, 2025
LeCarbonator
added a commit
to LeCarbonator/tanstack-form
that referenced
this issue
May 9, 2025
…k-form into form-group-api
LeCarbonator
added a commit
to LeCarbonator/tanstack-form
that referenced
this issue
May 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When calling
form.resetFieldValue()
on a nested field ('some.nested.field'
), it will not reset.The reason because it doesn't acknowledge the nested field name as a field path, and instead treats it as the literal key in the form values. See this line in
FormApi.ts
.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-3nazz9pj?file=src%2FApp.tsx
Steps to reproduce
Expected behavior
As a user, I expect the field name to be translated into the nested field value as that's what the typing implies.
How often does this bug happen?
Every time
Screenshots or Videos
Here's the outcome of what's actually happening behind the scenes:
Platform
Any browser
TanStack Form adapter
None
TanStack Form version
v1.10.0
TypeScript version
v5.8.3
Additional context
No response
The text was updated successfully, but these errors were encountered: