-
-
Notifications
You must be signed in to change notification settings - Fork 458
form.reset(value) is not resetting defaultValues to a provided value #1490
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
the question here is what's the ideal behaviour and if the default value meant to be always rendered when there isn't value or they have to be rendered only in the first rendering |
It seems to only be when form.reset is called in an async... https://stackblitz.com/edit/tanstack-form-9kpziquv?file=src%2Findex.tsx&preset=node You'll see from the stackblitz that form.reset() dose work correctly, but only when its not called inside async functions (click the reset, or reset with val)... However if you click the submit, then you'll get this weird wiping behaviour when form.reset() is called onSubmit() |
Thanks for the explanation! But it's a bit of a confusing behavior. I think it's quite a common use case of this method, when you need to reset a value after updating some data inside an asynchronous function. It would be great if this method would work correctly in this case too, so that we wouldn't have to invent ways around it. |
@ilialksv, no I think you've misunderstood me, I think it's a bug... only, I was stating where its happening. 😄 I've narrowed it down a little further, form core handles this correctly, the react adaptor is where this appears to be happening, well it might be happening in the other adapters I haven't checked. Theres a few issues like this that have opened in the past couple days, let me dig around a bit. [update]
|
@harry-whorlow Got it! Thanks for clarifying and for looking into it further. By the way, I just wanted to express my appreciation for this package. It has been a great help in my projects. Thank you and the team for your hard work! |
I have a fix ready over at 1494, I just need a CR and it should be deployed... sorry for the delay 😄 |
That’s great news! Thanks for getting this sorted out so quickly. Really looking forward to the release) |
Describe the bug
It seems like
form.reset(value)
is updatingdefaultValues
, but by the next renderdefaultValues
are being reset to the initially provided ones. So, as a result, there is no difference whether to callform.reset(value)
or justform.reset()
because they lead to the same result.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-x8k3rfrs?file=src%2FApp.tsx
Steps to reproduce
defaultValues
are being reset to the new ones (you can see it in console).defaultValues
are back to the initial ones.Expected behavior
As a user I expect that
defaultValues
are updated with the values provided toform.reset
method and not being reset to the initialdefaultValues
.How often does this bug happen?
Every time
Screenshots or Videos
no-reset.mp4
Platform
TanStack Form adapter
react-form
TanStack Form version
v1.9.1
TypeScript version
v5.8.3
Additional context
No response
The text was updated successfully, but these errors were encountered: