Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jaredpalmer/formik
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Apr 6, 2018
2 parents 65aae84 + 952a084 commit 636a670
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion examples/Arrays.js
Expand Up @@ -27,7 +27,7 @@ const SignIn = () => (
<div>
{values.friends.length > 0 &&
values.friends.map((friend, index) => (
<div className="row">
<div className="row" key={index}>
<div className="col">
<label htmlFor={`friends.${index}.name`}>Name</label>
<Field
Expand All @@ -36,6 +36,7 @@ const SignIn = () => (
type="text"
/>
{errors.friends &&
errors.friends[index] &&
errors.friends[index].name &&
touched.friends &&
touched.friends[index].name && (
Expand All @@ -52,6 +53,7 @@ const SignIn = () => (
type="email"
/>
{errors.friends &&
errors.friends[index] &&
errors.friends[index].email &&
touched.friends &&
touched.friends[index].email && (
Expand Down
15 changes: 7 additions & 8 deletions src/Formik.tsx
Expand Up @@ -774,18 +774,17 @@ export function yupToFormErrors<Values>(yupError: any): FormikErrors<Values> {
/**
* Validate a yup schema.
*/
export function validateYupSchema<T>(
data: T,
export function validateYupSchema<T extends FormikValues>(
values: T,
schema: any,
sync: boolean = false,
context: any = {}
): Promise<void> {
let validateData: any = {};
for (let k in data) {
if (data.hasOwnProperty(k)) {
): Promise<Partial<T>> {
let validateData: Partial<T> = {};
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, {
Expand Down

0 comments on commit 636a670

Please sign in to comment.