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

Calling setFieldError in form onSubmit second time undoes error #6125

Open
1 of 2 tasks
mawallace opened this issue Apr 24, 2024 · 2 comments
Open
1 of 2 tasks

Calling setFieldError in form onSubmit second time undoes error #6125

mawallace opened this issue Apr 24, 2024 · 2 comments

Comments

@mawallace
Copy link

Dependencies check up

  • 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:

  1. Enter a valid email
  2. Click submit (an error appears)
  3. 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
@okanfidan
Copy link

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.

@Jenrykster
Copy link

I'm facing the same problem.
I was able to get the desired behavior by using setErrors though.

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

3 participants