Skip to content
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

Form resets to default values on some re-renders #742

Closed
AshotN opened this issue Jun 12, 2024 · 2 comments
Closed

Form resets to default values on some re-renders #742

AshotN opened this issue Jun 12, 2024 · 2 comments

Comments

@AshotN
Copy link

AshotN commented Jun 12, 2024

Describe the bug

The form resets to it's default state when using a HTML <dialog> element.

You can force it to persist if you manually mark it dirty and isTouched

I'm not sure what else can cause the bug, surely it's not limited to a dialog

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/eloquent-farrell-rdqdnz?file=%2Fsrc%2FApp.js%3A52%2C39

Steps to reproduce

Click "Open Dialog"

To cause the issue, press "Set Data" and once you close the dialog, the inputs will clear.

The "Set Data Dirty" will persist, until the dialog is re-opened. Then the form resets again anyway

Expected behavior

I would expect the form default data to only be set on initial render

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Mac OS
  • Browser: Firefox

TanStack Form adapter

react-form

TanStack Form version

0.21.0

TypeScript version

No response

Additional context

No response

@crutchcorn
Copy link
Member

We had a few issues causing this before, but 0.24.0 technically makes this API work.

However, you'll still find a bug without {touch: true} on setFieldValue - like so:

form.setFieldValue("firstName", val.firstName, { touch: true });

This option is a scourge (my fault) on TanStack Form and we're removing it (making it true default and renaming the property to opt-out, not opt-in behavior).

The fix for now is to:

  • Update to 0.24.0
  • Move all setFieldValues to {touch: true}

Closing, since we know about touch: true removal and are tracking here:

#660

@AshotN
Copy link
Author

AshotN commented Jun 28, 2024

Appreciate the update and everything Tanstack does. Excited for form to become stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants