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

[1.0.0] resetForm wipes out status #410

Open
halljus opened this issue Feb 1, 2024 · 4 comments
Open

[1.0.0] resetForm wipes out status #410

halljus opened this issue Feb 1, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@halljus
Copy link

halljus commented Feb 1, 2024

Describe the bug and the expected behavior

Resetting a form via return json(submission.reply({ resetForm: true })) wipes out everything in the response data except for { initialValue: null }. This prevents us from checking lastResult.status === 'success' (or form.status) to determine if the submission was successful.

If you don't reset the form and just respond with return json(submission.reply()), the status field is present and set to success as expected.

Shouldn't resetForm: true just wipe out the data or whatever Conform needs to know to reset the form, but preserve the status field (and possibly others if there are more that are unrelated to the form reset mechanic)?

Conform version

v1.0.0

Steps to Reproduce the Bug or Issue

  1. Respond from a Remix action handler with return json(submission.reply({ resetForm: true }))
  2. Observe both useActionData().status and form.status are undefined

https://stackblitz.com/edit/remix-run-remix-vu7byk?file=app%2Froutes%2F_index.tsx

What browsers are you seeing the problem on?

Chrome, Firefox, Microsoft Edge, Safari, Others

Screenshots or Videos

No response

Additional context

No response

@edmundhung edmundhung added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Feb 2, 2024
@edmundhung
Copy link
Owner

I have thought about this before but I am unsure whether it's a good idea to keep the status. Can you share your usecase with the success status here?

@halljus
Copy link
Author

halljus commented Feb 2, 2024

The use case is displaying some form of feedback to the user that their form submission was successful (particularly when using a fetcher and not navigating anywhere).

  1. User submits valid form
  2. Action does something (successfully)
  3. Goal is now to remain on the same route, reset the form so they can submit another thing, and notify them the first thing worked

The migration docs even say you can do it here:

export default function Example() {
  const lastResult = useActionData<typeof action>();
  const [form, fields] = useForm({
    // `lastSubmission` is renamed to `lastResult` to avoid confusion
    lastResult,
  });

  // We can now find out the status of the submission from the form metadata as well
  console.log(form.status); // "success", "error" or undefined
}

But that isn't true, currently (as far as I can tell).

@taylrd
Copy link

taylrd commented Feb 5, 2024

I am also trying to figure out a way to do this. I opened up a discussion before I saw this. It would be very helpful to have access to the status and, in my case, have access to the previously mutated data so the user will get the proper feedback.

@halljus
Copy link
Author

halljus commented Feb 8, 2024

I'm using the following workaround, but it feels pretty hacky. 🙂

return json({ ...submission.reply(), ...submission.reply({ resetForm: true }) });

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

No branches or pull requests

3 participants