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

408
Vistas
how to trigger validation in React Hook Form in React Native Expo Web

How can I manually trigger form validation in React Hook Form, I would like to achieve effect of handleSubmit, but in keypress event handler and handleSubmit does not seem to work outside onPress. In the onPress handler, my code looks like so

  <Button
        color={enter ? COLORS.greys["gray-100"] : COLORS.TERTIARY}
        textColor={COLORS.FONT_COLOR}
        onPress={handleSubmit((data) => onSubmit(data))}
      >
        Enter
      </Button>

and when I click this button and fields are invalid the error message shows up, I want to do this same if user clicks Enter, but this code does not work

  const changeView = (e: KeyboardEvent) => {
    if (e.key === "Enter") {
      handleSubmit((data) => onSubmit(data));
    }
  };
  useEffect(() => {
    document.body.addEventListener("keydown", changeView);
    return () => {
      document.body.removeEventListener("keydown", changeView);
    };
  }, []);

I use getValues hook with onSubmit to make it work, but if the fields are invalid the form is not being validated

  const changeView = (e: KeyboardEvent) => {
    if (e.key === "Enter") {
      onSubmit(getValues());
    }
  };

How can I validate the form in the event listener's handler?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you can use fromik to form library and yep library to validation this is usefull

about 4 years ago · Juan Pablo Isaza Denunciar
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