Reputation: 3416
I'm using Formik to build a simple form.
In my validation
method I'm checking to see if a name has been entered into the field. If it has not, then I print into the console - which is working fine.
validate={values => {
let errors = [];
if (!values.name) {
console.log("no name entered");
errors.name = "First name required";
}
//check if my values have errors
return errors;
}}
However, the <ErrorMessage />
component does nothing when the above condition is met:
<Field
type="text"
name="name"
placeholder="First Name"
/>
<ErrorMessage name="name" />
Why is this?
Upvotes: 2
Views: 39
Reputation: 577
The issue is that you have let errors = [];
instead of let errors = {};
.
Upvotes: 3