When I open the screen, I don't see any validation error until I first submit the form. Once the email address is entered correctly and the form is submitted by hitting the button, the form logic works correctly. An alert is shown & the field is reset (intentional)
However, once I close the the alert, Formik still shows me an error that I must enter an email address (required field). Is it possible to reset the error too? Just like it was when I first opened the screen? I want this error to appear only when I am submitting the form without typing something.
Snippets of my code:
Resetting the value here:
const initialValues: FormValues = {
email: '',
};
const handleSubmitForm = React.useCallback(
(values: FormValues, helpers: FormikHelpers<FormValues>) => {
console.log('Submitted');
loadUsers({
variables: {
where: { email: values.email },
},
});
values.email = '';
},
[loadUsers],
);
<Formik
initialValues={initialValues}
onSubmit={handleSubmitForm}
validationSchema={validationSchema}>
{({
handleChange,
handleBlur,
handleSubmit,
values,
}) => (
<View style={styles.searchFieldContainer}>
<View
style={styles.form}
>
<FieldInput
handleChange={handleChange}
handleBlur={handleBlur}
value={values.email}
fieldType="email"
/>
<ErrorMessage
name="email"
render={(msg) => (
<Text style={styles.errorText}>
{msg}
</Text>
)}
/>
</View>
<View style={styles.buttonContainer}>
<Button
rounded
style={styles.button}
onPress={handleSubmit}>
<Text style={styles.text}>
Add Friend{' '}
</Text>
</Button>
</View>
</View>
)}
</Formik>