From 164b139b9e3abe1ee06b0a1d560b189526fd3388 Mon Sep 17 00:00:00 2001 From: Saad Quadri Date: Sun, 1 Apr 2018 20:52:14 -0400 Subject: [PATCH 1/2] fix Arrays example (#550) --- examples/Arrays.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/Arrays.js b/examples/Arrays.js index 7afc8b25a..02cbb1b97 100644 --- a/examples/Arrays.js +++ b/examples/Arrays.js @@ -27,7 +27,7 @@ const SignIn = () => (
{values.friends.length > 0 && values.friends.map((friend, index) => ( -
+
( type="text" /> {errors.friends && + errors.friends[index] && errors.friends[index].name && touched.friends && touched.friends[index].name && ( @@ -52,6 +53,7 @@ const SignIn = () => ( type="email" /> {errors.friends && + errors.friends[index] && errors.friends[index].email && touched.friends && touched.friends[index].email && ( From 952a084d88d36bce25af5423913eb4fd43206bcf Mon Sep 17 00:00:00 2001 From: Piotr Witek Date: Wed, 4 Apr 2018 06:55:49 +0200 Subject: [PATCH 2/2] improved validateYupSchema types (#554) --- src/Formik.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Formik.tsx b/src/Formik.tsx index 230311ab8..44186dc0b 100644 --- a/src/Formik.tsx +++ b/src/Formik.tsx @@ -774,18 +774,17 @@ export function yupToFormErrors(yupError: any): FormikErrors { /** * Validate a yup schema. */ -export function validateYupSchema( - data: T, +export function validateYupSchema( + values: T, schema: any, sync: boolean = false, context: any = {} -): Promise { - let validateData: any = {}; - for (let k in data) { - if (data.hasOwnProperty(k)) { +): Promise> { + let validateData: Partial = {}; + for (let k in values) { + if (values.hasOwnProperty(k)) { const key = String(k); - validateData[key] = - (data as any)[key] !== '' ? (data as any)[key] : undefined; + validateData[key] = values[key] !== '' ? values[key] : undefined; } } return schema[sync ? 'validateSync' : 'validate'](validateData, {