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

Fix for checkboxes with an initial value of undefined #2188

Merged
merged 1 commit into from Jan 9, 2020

Conversation

zachintosh
Copy link
Contributor

@zachintosh zachintosh commented Jan 9, 2020

v2.1.1 introduced a bug with checkboxes where they require an initial value in order to work. This is reproducible and is fixed by back-pinning to v2.1.0. Please view this codesandbox:

Edit solitary-smoke-qp6kx

The getValueForCheckbox function in Formik.tsx was updated to handle checkbox values better, but it introduced a situation where a checkbox with an undefined value would throw an error, since getValueForCheckbox was assuming it was an array.

Stack Trace:

Uncaught TypeError: Cannot read property 'indexOf' of undefined
    at getValueForCheckbox (formik.cjs.development.js:1216)
    at eval (formik.cjs.development.js:735)
    at eval (formik.cjs.development.js:750)
	...

Here is the line where it breaks:

const index = currentValue.indexOf(valueProp);

The changes in this PR just shuffle the logic a tiny bit to guarantee this check does not occur unless currentValue is an array.

resolves #2184

@vercel
Copy link

vercel bot commented Jan 9, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/jared/formik-docs/7a5n6hdml
✅ Preview: https://formik-docs-git-fork-zachintosh-fix-getvalueforcheckbox.jared.now.sh

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

Successfully merging this pull request may close these issues.

Checkbox with undefined/null value results in an error
2 participants