From 3495a25f7f3ecf6db0e2e3dfdfc59f89866eba7c Mon Sep 17 00:00:00 2001 From: Mike Hiley Date: Mon, 17 Aug 2020 15:26:47 -0500 Subject: [PATCH 1/2] Use low priority form validation for FieldArray --- packages/formik/src/FieldArray.tsx | 2 +- packages/formik/src/Formik.tsx | 2 ++ packages/formik/src/types.tsx | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/formik/src/FieldArray.tsx b/packages/formik/src/FieldArray.tsx index e92bc8a42..029f58718 100644 --- a/packages/formik/src/FieldArray.tsx +++ b/packages/formik/src/FieldArray.tsx @@ -144,7 +144,7 @@ class FieldArrayInner extends React.Component< ) && this.props.formik.validateOnChange ) { - this.props.formik.validateForm(this.props.formik.values); + this.props.formik.validateFormWithLowPriority(this.props.formik.values); } } diff --git a/packages/formik/src/Formik.tsx b/packages/formik/src/Formik.tsx index c1aa832c3..f36f583e2 100755 --- a/packages/formik/src/Formik.tsx +++ b/packages/formik/src/Formik.tsx @@ -845,6 +845,7 @@ export function useFormik({ resetForm, validateForm: validateFormWithHighPriority, + validateFormWithLowPriority, validateField, setErrors, setFieldError, @@ -982,6 +983,7 @@ export function useFormik({ setValues, submitForm, validateForm: validateFormWithHighPriority, + validateFormWithLowPriority, validateField, isValid, dirty, diff --git a/packages/formik/src/types.tsx b/packages/formik/src/types.tsx index 0a9f79bfb..2f9d96cb8 100644 --- a/packages/formik/src/types.tsx +++ b/packages/formik/src/types.tsx @@ -97,6 +97,8 @@ export interface FormikHelpers { ) => void; /** Validate form values */ validateForm: (values?: any) => Promise>; + /** Validate form values w/o blocking UI */ + validateFormWithLowPriority: (values?: any) => void; /** Validate field value */ validateField: (field: string) => void; /** Reset form */ From 9330a310920ed2d2c3009071ba9fd3e061ca074b Mon Sep 17 00:00:00 2001 From: Mike Hiley Date: Mon, 17 Aug 2020 15:55:11 -0500 Subject: [PATCH 2/2] Fix test failures due to validateFormWithLowPriority --- packages/formik/test/withFormik.test.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/formik/test/withFormik.test.tsx b/packages/formik/test/withFormik.test.tsx index f4515a48b..d6fbc5f31 100644 --- a/packages/formik/test/withFormik.test.tsx +++ b/packages/formik/test/withFormik.test.tsx @@ -109,6 +109,7 @@ describe('withFormik()', () => { unregisterField: expect.any(Function), validateField: expect.any(Function), validateForm: expect.any(Function), + validateFormWithLowPriority: expect.any(Function), validateOnBlur: true, validateOnMount: false, validateOnChange: true, @@ -184,6 +185,7 @@ describe('withFormik()', () => { setValues: expect.any(Function), validateField: expect.any(Function), validateForm: expect.any(Function), + validateFormWithLowPriority: expect.any(Function), submitForm: expect.any(Function), } )