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

132
Views
How can I get data from a form when user clicks submit and validate it before submitting in react?

When a user clicks submit button on a page, and it fails validation, I want to be able to compare the data they tried to submit against an existing db and use that to display a warning depending on which fields they changed (formik.touched isn't working so trying a workaround).

This is the return function with onSubmit where I want to access data user tried to submit:

return (
    <Layout
      title={PROFILE_PAGE_TITLE}
      verticalNavMenu={<VerticalNavMenu actions={PROFILE_NAV_ACTIONS} />}
    >
      {!employeeDetailsPending && !employeeDetailsError && !configPending && !configError ? (
        <FormikProvider value={formik}>
          <form onSubmit={formik.handleSubmit}> ...etc etc

The formik onSubmit functions have the following:

  const formik = useFormik({
    initialValues,
    validationSchema: validationSchema,
    enableReinitialize: true,
    onSubmit: (values) => {
      dispatch(putAndi(prepareAndiForSubmission(values), authUser?.id));
    },
  });

  const prepareEmployeeForSubmission = (values) => {
    const employee = { ...values };
    if (!employee.gender.includes('Other')) {
      employee.genderText = null;
    }
    return employee;
  };

And finally, the validation schema has a useState hook, which takes parameter of a different js file, which has the following

export const AndiDetailsSchema = yup.object({
  title: yup.string().required('Title is required').nullable(),
  firstName: yup.string().required('First name is required').nullable(), ...etc etc
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!