Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda