final-form / final-form/react-final-form
Pass external variable to onSubmit
- Dominant language
- JavaScript
- Stars
- 7.4k
- Forks
- 497
- PR merge metrics
- No merged PRs in 30d
Description
### Are you submitting a **bug report** or a **feature request**?
Feature request
### What is the current behavior?
`onSubmit` only receives predefined arguments without an option to pass some custom data through `handleSubmit()` or `form.submit()`
### What is the expected behavior?
It would be very useful if `handleSubmit` could accept more than one variable, and pass these variables to the `onSubmit` call.
### Use case
Consider having a form with two actions: Save and Send to moderation
In both cases the form should first go through basic validation, then save the data, but if user has chosen to "Send to moderation", we should make an additional validation check and require more fields, and if this validation passes - make one more api call.
It is currently possible to take the values from the form's render props and make a custom callback. However, the only non-hacky way to throw submit errors is to return them from `onSubmit`. Therefore, unless we are able to pass some custom data, in this case - user's action, we would not be able to achieve the desired behaviour without using some hacks like saving the action via the `useRef` before calling `onSubmit`.
Contributor guide
Assessment
This issue has not been assessed yet.