diff --git a/src/FastField.tsx b/src/FastField.tsx index 2f1595c5d..9ab0e0d68 100644 --- a/src/FastField.tsx +++ b/src/FastField.tsx @@ -110,20 +110,18 @@ class FastFieldInner extends React.Component< ) { if (this.props.shouldUpdate) { return this.props.shouldUpdate(props, this.props); - } else if ( - getIn(this.props.formik.values, this.props.name) !== - getIn(props.formik.values, this.props.name) || - getIn(this.props.formik.errors, this.props.name) !== - getIn(props.formik.errors, this.props.name) || - getIn(this.props.formik.touched, this.props.name) !== - getIn(props.formik.touched, this.props.name) || - Object.keys(this.props).length !== Object.keys(props).length || - this.props.formik.isSubmitting !== props.formik.isSubmitting - ) { - return true; - } else { - return false; } + return ( + props.formik.lastTouched === this.props.name && + (this.props.formik.isSubmitting !== props.formik.isSubmitting || + Object.keys(this.props).length !== Object.keys(props).length || + getIn(this.props.formik.values, this.props.name) !== + getIn(props.formik.values, this.props.name) || + getIn(this.props.formik.errors, this.props.name) !== + getIn(props.formik.errors, this.props.name) || + getIn(this.props.formik.touched, this.props.name) !== + getIn(props.formik.touched, this.props.name)) + ); } componentDidMount() { diff --git a/src/Formik.tsx b/src/Formik.tsx index ddcb1b6d8..e5ce080b9 100755 --- a/src/Formik.tsx +++ b/src/Formik.tsx @@ -329,6 +329,7 @@ export class Formik extends React.Component< prevState => ({ ...prevState, values: setIn(prevState.values, field!, val), + lastTouched: field, }), () => { if (this.props.validateOnChange) { @@ -454,6 +455,7 @@ export class Formik extends React.Component< this.setState(prevState => ({ touched: setIn(prevState.touched, field, true), + lastTouched: field, })); if (this.props.validateOnBlur) { @@ -482,6 +484,7 @@ export class Formik extends React.Component< prevState => ({ ...prevState, touched: setIn(prevState.touched, field, touched), + lastTouched: field, }), () => { if (this.props.validateOnBlur && shouldValidate) { @@ -509,6 +512,7 @@ export class Formik extends React.Component< isValidating: false, errors: {}, touched: {}, + lastTouched: undefined, error: undefined, status: undefined, values, diff --git a/src/types.tsx b/src/types.tsx index e21c2fa53..5ab72d17d 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -40,6 +40,8 @@ export interface FormikState { errors: FormikErrors; /** map of field names to whether the field has been touched */ touched: FormikTouched; + /** Name of the field which trigger the last update event */ + lastTouched?: string; /** whether the form is currently validating */ isValidating: boolean; /** whether the form is currently submitting */