Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
work validation after press Enter on Formik library

when i click submit butten(After entering the values ​​in the input ) , every things is ok, but when press enter , again every things is ok but focus remain on input and click any where out side input , validation input work and this is bad. how can solve this logical problem?

const InsertTodoForm = () => {
  const validation = (values) => {
    const errros = {};
    console.log(values);
    if (!values.name) {
      errros.name = "name is req";
    } else if (values.name.trim().length < 5) {
      errros.name = "name < 5";
    }
    return errros;
  };
  const dispatch = useDispatch();
  return (
    <Fragment>
      <Formik
        initialValues={{
          name: "",
          complete: false,
        }}
        validate={validation}
        onSubmit={(out, operation) => {
          dispatch(
            insertTodo({ ...out, id: Math.floor(Math.random() * 2000) })
          );
          operation.resetForm();
        }}
        validateOnMount={true}
      >
        <Form>
          <label>
            name
            <Field type="text" placeholder="name..." name="name" id="f" />
            <ErrorMessage component={"p"} name="name" />
          </label>
          <hr />
          <Field type="checkbox" name="complete" />
          <hr />
          <button type="submit">submit</button>
        </Form>
      </Formik>
    </Fragment>
  );
};

export default InsertTodoForm;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!