Calling setFieldError in form onSubmit second time undoes error
Dependencies check up
- [X] I have verified that I use latest version of all @mantine/* packages
What version of @mantine/* packages do you have in package.json?
7.8.1
What package has an issue?
@mantine/core
What framework do you use?
Next.js
In which browsers you can reproduce the issue?
None
Describe the bug
Thanks for the awesome library!
I noticed some weird behavior when calling setFieldError in the onSubmit handler. Namely, when you submit multiple times without changing the text input, the error disappears.
In the linked code sandbox:
- Enter a valid email
- Click submit (an error appears)
- Click submit again (the error disappears)
I would not expect the error to disappear.
As a workaround, I have disabled the button while there are errors. I did this using disabled={Object.keys(form.errors).length > 0}, but please let me know if there's a cleaner way (it might be nice to be able to call form.hasErrors() or something).
If possible, include a link to a codesandbox with a minimal reproduction
https://codesandbox.io/p/sandbox/spring-currying-3zc49y?file=%2Fsrc%2FApp.tsx%3A11%2C36
Possible fix
No response
Self-service
- [ ] I would be willing to implement a fix for this issue
I get the same error.
When I use setFieldError in the onSubmit event, different things happen. The first time the error appears, it is hidden in the other submit operation.
Then it appears again when I submit again.
I'm facing the same problem.
I was able to get the desired behavior by using setErrors though.
Can confirm. This is still an issue in the latest release.
Duplicate of https://github.com/mantinedev/mantine/issues/6101