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

406
Views
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 answers
Answer question

0

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

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