-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Modularize the Form onSubmit method #216
Comments
Is your motivation to execute different logic when a certain button is clicked? |
Yes, different logic for each button but sharing the same form/data. For my particular case now it's different api endpoints for saving the data. |
This is already possible. Just use a button with an event handler and check with <Form>
<Field>...</Field>
<button onclick={async () => {
if (await validate(form)) {
// ...
}
}}>
Action 1
</button>
<button onclick={async () => {
if (await validate(form)) {
// ...
}
}}>
Action 2
</button>
</Form> |
Right, but if I also want to update the submit states and response state, I am essentially rewriting the entire function that's in the Form onSubmit event. Granted, it's still not that much, but this sparked my idea to just pull it out to its own method. |
Thanks for your feedback! I will consider it when rewriting the library at some point in the future. |
Summary
I think it would be useful to separate out the
onSubmit
logic inside theForm
component into it's own method.However, it seems like this library is planned on being rewritten soon so maybe this is just something to think about for that.
Motivation:
Using multiple submit type actions seems more complicated then needed
Current Options (Maybe there are better ways)
Implentation
handleSubmit(form,onSubmit,options?,event?)
Example
Love the library and thanks for the work.
I can work on a PR if needed (This would be my first time)
The text was updated successfully, but these errors were encountered: