formik icon indicating copy to clipboard operation
formik copied to clipboard

Validation not working in Firefox

Open carolinmaisenbacher opened this issue 7 years ago • 7 comments

🐛 Bug report

Current Behavior

When running a formik form, with a Yup validationSchema in a Firefox browser, form errors are not recognized.

To reproduce the error, I used the basic formix sandbox example and tested it with lambdatest, which sets up a whole vm, to make sure this error has nothing to do with my machine.

The only thing I switched was upgrading formik v.2.0.3.

First I tested with Chrome 77, on Windows 10. Here everything works as expected. Screenshot 2019-11-06 10 24 26

However, in Firefox, here I used 69, on Windows 10, the error is not displayed, nor does it appear in the form state. Screenshot 2019-11-06 10 25 42

Both times I typed in an invalid email and unfocused the field afterwards.

Expected behavior

I expected to see the email error message in the forms state.

Reproducible example

Use the basic formik codebox example and run it in a firefox example. Try to type an invalid email. https://codesandbox.io/s/formik-example-22biw

Additional context

I myself am running on MacOs Mojave and the Firefox Developer Edition and I stumbled upon this problem using formik for a larger application. There formik does not only not validate, but the whole application crashed, when a validation error occurs.

I also tested it with the original sandbox example which uses v1.5.8 and the same error occurs.

Your environment

Software Version(s)
Formik 2.0.3
React 16.8.6
Browser Firefox 69
Operating System Windows

carolinmaisenbacher avatar Nov 06 '19 02:11 carolinmaisenbacher

I encountered this as well after upgrading to 2.0.3. For now I have reverted to 1.5.8.

Software Version(s)
Formik 2.0.3
Yup 0.27.0
React 16.11.0
Browser Firefox 70
OS MacOS

Edit - I retested this issue with formik 2.0.4 and react 16.12.0 in FF but the issue is still present.

VincentvD avatar Nov 08 '19 16:11 VincentvD

Works for me with Formik 2.0.4, Firefox 70, Win 10, React 16.12.0, bundle made with create-react-app 3.1.1.

While digging around the issue I've found that the validation silently fails on 1.5.7, but shows a warning on 2.0.4: An unhandled error was caught during validation in <Formik validationSchema />. The difference is likely caused by this change #1575 that introduced the warning.

When I stopped in the debugger on runValidationSchema function I've found that the error received by Formik is not a ValidationError as expected, but a different one with a message "Unexpected frame by generating stack." that wraps the original ValidationError. That's why Formik doesn't read the errors from the Yup validation.

This looks like an issue with a codesandbox environment, as I don't see it when set up locally. This issue on CodeSandbox looks related: codesandbox/codesandbox-client#1744. For folks above I'd recommend to try to build it locally, or with a different bundler/polyfill, and if those don't help take a look at the above-mentioned functions in the debugger.

dbanisimov avatar Nov 20 '19 17:11 dbanisimov

I was planning on creating a small example (outside of codesandbox) to test this. But I first checked my previous sandbox example with all updated deps and I cannot reproduce this issue.

VincentvD avatar Dec 06 '19 15:12 VincentvD

I came across the issue again. This time I realised, the validation only fails, when the developer tools are opened while editing a form in Firefox Developer Edition.

That makes the bug in my opinion irrelevant and I would suggest to close this issue.

carolinmaisenbacher avatar Feb 17 '20 22:02 carolinmaisenbacher

In my case, when using an input with e.g. type email, the browser blocks the actual form submit because of its' own validation checks and so does not mark the fields as touched. This way the error message is not shown when you enter a non-email value in the email field and hit submit.

rvanlaarhoven avatar Feb 26 '20 09:02 rvanlaarhoven

Screen Shot 2020-02-26 at 10 09 54 AM

Just tested in 2.1.4. Works as expected.

Hitting enter to submit while in an input will not trigger a blur event if there is a browser input validation error in FF. This can be seen in screenshot with <input type="email" />.

jaredpalmer avatar Feb 26 '20 15:02 jaredpalmer

https://codesandbox.io/s/formik-example-8jll6

jaredpalmer avatar Feb 26 '20 15:02 jaredpalmer