mantine icon indicating copy to clipboard operation
mantine copied to clipboard

Calling setFieldError in form onSubmit second time undoes error

Open mawallace opened this issue 1 year ago • 2 comments

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:

  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

mawallace avatar Apr 24 '24 02:04 mawallace

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.

okanfidan avatar May 03 '24 15:05 okanfidan

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

Jenrykster avatar May 09 '24 16:05 Jenrykster

Can confirm. This is still an issue in the latest release.

Xeretis avatar May 26 '24 15:05 Xeretis

Duplicate of https://github.com/mantinedev/mantine/issues/6101

rtivital avatar May 26 '24 17:05 rtivital