Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

410
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda