- Trying to make validate fields on form submit. (Same time, onblur and onchange must be active too) But when I leave field empty, and submit form. It doesnt give any error.
How can this be possible?
And my second question is; when I post values to my rest api. It may return 400 error, and I want to use these error to my validation fields. Here's my api response:
{ "msg": "Missing required fields", "errors": { "name": [ "validation.required" ], "country": [ "validation.required" ], "city": [ "validation.required" ] } }
It must be let validation errors to name field, city and country fields. How can this be possible?
<Formik
initialValues={values}
enableReinitialize={true}
validationSchema={ProductEditSchema}
validateOnChange={true}
validateOnBlur={true}
onSubmit={(values) => {
saveLocation(values);
}}
>
......
<Button
size="large"
className={classes.button}
variant="contained"
color="secondary"
onSubmit={() => handleSubmit()}
>
{intl.formatMessage({ id: "GENERAL.SUBMIT" })}
</Button>
</Form>
</>
)}
</Formik>