Skip to content

Commit 90b4a99

Browse files
andrejcesenAlmouro
authored andcommitted
fix: validation on tapping keyboard's ‘done'
Tapping ‘done’ button before triggered validation twice - first when calling submitForm, and secondly onBlur (keyboard dismiss). Now it only happens on submitForm and is consistent on waiting for async validation.
1 parent 97437ed commit 90b4a99

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/makeReactNativeField.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import withFormik from "./withFormik";
55

66
const makeReactNativeField = compose(
77
withFormik,
8-
mapProps(({ formik: { setFieldValue, setFieldTouched, values }, name, ...props }) => ({
8+
mapProps(({ formik: { setFieldValue, setFieldTouched, values, isSubmitting }, name, ...props }) => ({
99
value: _.get(values, name),
1010
...props,
1111
name,
@@ -14,7 +14,9 @@ const makeReactNativeField = compose(
1414
if (props.onChangeText) props.onChangeText(text);
1515
},
1616
onBlur: () => {
17-
setFieldTouched(name);
17+
// validate onBlur only while not submitting
18+
// this prevents validating twice in succession when clicking 'done' on keyboard - first onSubmitEditing, then onBlur
19+
setFieldTouched(name, true, isSubmitting ? false : true);
1820
if (props.onBlur) props.onBlur();
1921
}
2022
}))

0 commit comments

Comments
 (0)