Skip to content

Commit

Permalink
Patch to getValueForCheckbox to resolve issues with undefined values (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zachintosh authored and jaredpalmer committed Jan 9, 2020
1 parent fee503e commit 6f4aadd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@ function getValueForCheckbox(

// If the currentValue was not a boolean we want to return an array
let currentArrayOfValues = []
let isValueInArray = false
let index = -1

if (!Array.isArray(currentValue)) {
// eslint-disable-next-line eqeqeq
Expand All @@ -1143,10 +1145,10 @@ function getValueForCheckbox(
} else {
// If the current value is already an array, use it
currentArrayOfValues = currentValue
index = currentValue.indexOf(valueProp);
isValueInArray = index >= 0;
}

const index = currentValue.indexOf(valueProp);
const isValueInArray = index >= 0;

// If the checkbox was checked and the value is not already present in the aray we want to add the new value to the array of values
if (checked && valueProp && !isValueInArray) {
Expand Down

1 comment on commit 6f4aadd

@vercel
Copy link

@vercel vercel bot commented on 6f4aadd Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.