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

values.hasOwnProperty is not a function in v2 #2138

Closed
BjoernRave opened this issue Dec 19, 2019 · 5 comments · Fixed by #2177 or #2178
Closed

values.hasOwnProperty is not a function in v2 #2138

BjoernRave opened this issue Dec 19, 2019 · 5 comments · Fixed by #2177 or #2178

Comments

@BjoernRave
Copy link
Contributor

BjoernRave commented Dec 19, 2019

When submitting my form before it runs any validation it throws the following error:

TypeError: values.hasOwnProperty is not a function
    at prepareDataForValidation (http://localhost:3000/_next/static/development/pages/movements/new.js:103559:16)
    at prepareDataForValidation (http://localhost:3000/_next/static/development/pages/movements/new.js:103571:21)
    at validateYupSchema (http://localhost:3000/_next/static/development/pages/movements/new.js:103545:22)
    at http://localhost:3000/_next/static/development/pages/movements/new.js:102858:83
    at http://localhost:3000/_next/static/development/pages/movements/new.js:102910:84
    at http://localhost:3000/_next/static/development/pages/movements/new.js:102955:12
    at http://localhost:3000/_next/static/development/pages/movements/new.js:103653:24
    at http://localhost:3000/_next/static/development/pages/movements/new.js:103278:12
    at http://localhost:3000/_next/static/development/pages/movements/new.js:103653:24
    at http://localhost:3000/_next/static/development/pages/movements/new.js:103364:5
    at http://localhost:3000/_next/static/development/pages/movements/new.js:103653:24
    at HTMLUnknownElement.callCallback (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:587:14)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:636:16)
    at invokeGuardedCallback (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:691:31)
    at invokeGuardedCallbackAndCatchFirstError (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:705:25)
    at executeDispatch (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:835:3)
    at executeDispatchesInOrder (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:860:5)
    at executeDispatchesAndRelease (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:964:5)
    at executeDispatchesAndReleaseTopLevel (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:973:10)
    at forEachAccumulated (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:945:8)
    at runEventsInBatch (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:990:3)
    at runExtractedPluginEventsInBatch (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:1131:3)
    at handleTopLevel (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:6054:5)
    at batchedEventUpdates$1 (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:24652:12)
    at batchedEventUpdates (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:1666:12)
    at dispatchEventForPluginEventSystem (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:6145:5)
    at attemptToDispatchEvent (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:6261:5)
    at dispatchEvent (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:6165:19)
    at unstable_runWithPriority (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:29238:12)
    at runWithPriority$2 (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:12400:10)
    at discreteUpdates$1 (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:24668:12)
    at discreteUpdates (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:1689:12)
    at dispatchDiscreteEvent (http://localhost:3000/_next/static/development/dll/dll_5b0563bdfc01362a831f.js?ts=1576760335824:6132:3)

I created a wrapper with formik and this wrapper is not throwing this error on some forms, but on some it is. Not really sure why.

It works with formik 1.5.8

If you need more info, I am happy to provide. I thought this might be enough, otherwise I can add you as collaborator to my project

@jaredpalmer
Copy link
Owner

Can you create a sandbox to reproduce?

@emrosenf
Copy link
Contributor

emrosenf commented Jan 7, 2020

I'm experiencing this too. Looks like a simple one line fix in prepareDataForValidation. See this issue

Change L1074

if (values.hasOwnProperty(k)) {

To

if (Object.prototype.hasOwnProperty.call(values, k)) {

@jaredpalmer
Copy link
Owner

Feel free to submit PR. Be sure to reference that urql issue too

jaredpalmer pushed a commit that referenced this issue Jan 7, 2020
Closes #2138

From time to time, Formik may be passed Object-like
data that does not inherit from the Object prototype.
In these cases, hasOwnProperty is not defined, and
prepareDataForValidation will throw.

The fix is to use Object.prototype to call
hasOwnProperty on the data.

See urql-graphql/urql#343
@BjoernRave
Copy link
Contributor Author

@emrosenf wow, same PR, same moment 🙌

@emrosenf
Copy link
Contributor

emrosenf commented Jan 7, 2020

Good timing @BjoernRave! Thanks for your hard work @jaredpalmer, Formik is a super useful library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants