-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imperative form submit
method
#11801
base: master
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
It's failing due to an increased bundle size, up to 10.23KB. Not sure how to incorporate the UUID generation without affecting bundle size. |
Hey @bluebill1049 , I believe this is a feature that could benefit many users as well, I'd love your feedback for it when possible. |
hi, could we just do this? <form onSubmit={handleSubmit(....)}>
<input type="text" name="name" />
</form>
<input type="submit" form="myform" value="Update"/> |
Hey @bluebill1049 , that assumes we only want to trigger a submit with a button click. But we may want to submit a form programmatically by other means. Also, having the submit input/button outside the form only works when setting up the form with the proper ID (this PR takes care of that). By adding |
Any further thoughts @bluebill1049 ? |
Hello.
We've created a patch for this library, which has worked wonderfully. This change allows users to submit forms imperatively with a new
submit
function returned by the form hook, a feature that users have long requested (#566). This is done by giving the form component a unique ID that is stored within the form context of the RHF instance.Previously, one had to restructure their components by wrapping items and buttons into the form context to gain access to the handleSubmit function and trigger it manually. Now, we can do this:
The beauty is that one can trigger the form from any component with the
form.id
, which is now returned by theuseFormContext();
hook. You can also specify your own ID value for the form if you want to have control over it, but if not then RHF will generate a UUID.