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: true
doesn't work?
#434
Comments
Thanks for getting me a repo. This reason why it doesn't work is because of the time the lastResult is updated and the time the defaultValue updated is different in Remix 😅 Conform will reset the form the moment One solution for now is to delay when you update the lastResult: !isSubmitting ? lastResult : null, |
Oh! That's funny, as I used to do exactly that but for a totally different reason (disabling inputs while submitting). I took it out for v1 because it was no longer a problem since you stopped using the Constraint Validation API, but I guess it's still needed - just for a totally different reason. 😅 |
Yeah 😅 This might be resolved with single fetch. I probably should talk to the team and see if they wanna change this behaviour together. |
I wanted to get the form back to a clean state. I feel it should always set the state to clean when the form was submitted successfully independently of the form being reset or not but it does not look like that is happening. Trying to reset the form would also keep the most recent values before save for me, and the proposed workaround did not work, so I did a potentially heavy workaround, where I simply change the form Any other (cleaner) way? |
Maybe adding a utility function on the useForm hook that can set the form to clean state would be nice both for this use case and other use cases - but automatically handling it better would of course be preferred :) |
It would be great if you can provide a repo so I can understand it better
You can always trigger a form reset manually either with formElement.reset() or dispatching a reset intent with |
I can try to provide that, but not sure how easy it is to isolate/re-create the issue or if this is due to other parts I have going in the same interface (for example I have a tiptap editor and the implementation there required a less than optimal approach). Changing form
The one thing I struggle the most with, with this library, is that it uses these proxy objects, so debugging out the form or field does not show the methods available and I have not found a way to do that (maybe you have?). Of course if the docs covered more this would be less of an issue and I totally understand you have not been able to improve on that yet, and I wish I had time and knowledge to help with that. I'm considering alternative approaches to reseting the form. One way would be to do the |
We should add a tips to the remix integration docs. |
Describe the bug and the expected behavior
Resetting a form to new default values after a successful submission does not seem to work. Sending a
submission.reply({ resetForm: true })
response does reset theform.dirty
tofalse
, but the values remain the original ones. The reproduction below illustrates it well, including a workaround.Conform version
v1.0.0
Steps to Reproduce the Bug or Issue
Full reproduction here:
https://stackblitz.com/edit/remix-run-remix-4j3ltb?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
The text was updated successfully, but these errors were encountered: