Problem to dispatch handleSubmit outside submit event. #10962
Replies: 2 comments
-
Ok, I solved this by placing it directly in the button's onClick and transforming it into a submit type and placing a second parameter in onSubmit <button type="submit" onClick={handleSubmit(values => onSubmit(values, true))}>
Outside call
</button> |
Beta Was this translation helpful? Give feedback.
0 replies
-
You might be able to leverage the HTML function Form() {
const { handleSubmit } = useForm()
function onSubmit(data, event) {
console.log(event.nativeEvent.submitter.name)
}
return (
<>
<form id="my-form" onSubmit={handleSubmit(onSubmit)}>
<button type="submit" name="inside">
Submit Inside
</button>
</form>
<button type="submit" name="outside">
Submit Outside
</button>
</>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I have a listing scenario, where I use the react-hook-form library to control the filters. Within this filter, there are two scenarios, one where the user can perform a search, thus resetting the API return and making a new call, made through the form's onSubmit itself. However, there is a call that brings 10 more records, on top of the existing filter, where in this "load more", I cannot trigger the handleSubmit event.
I read in some places that it should work using just handleSubmit() with a callback function inside, but apparently I'm doing something wrong.
I tried to simulate a similar behavior into codesandbox, here's the link: https://3rxdgs.csb.app/
Beta Was this translation helpful? Give feedback.
All reactions