New feature, allow for an optional onChange property to be supplied to formik that would allow external notification of changes before things are submitted.
For instance, we often start out not needing to know about form values until they are submitted, but occasionally we do need to do additional things based on the values as they change. So Formik could allow us to pass in an additional onChange property which will be called whenever the values change. This would allow external systems to be called as needed.
There is no way to notify about field changes until submitted.
Optionally it would be good to have the ability to notify about changes. This would allow certain fields to be monitored and enable updates based on changes.
Add optional property onChange to formik. If a function is provided then it will be called with the latest values and formik bag every time any field changes.
onChange: (values: Values, formikBag: FormikBag) {
// I can be notified of the updated values and can use them
}
See #401
yes, #401 would be a nice way to handle that. It would make it easy to know when a specific value changed, etc. Thanks.
@jaredpalmer The linked proposal was abandoned, but there are plenty of use cases for onChange
. I think it's worth re-opening this. Here's one use case:
A typical filter form doesn't have a submit button, but every interaction with selects, checkboxes, radios etc immediately update the UI. It's convenient to have an onChange
as proposed above to update the UI.
Most helpful comment
@jaredpalmer The linked proposal was abandoned, but there are plenty of use cases for
onChange
. I think it's worth re-opening this. Here's one use case:Filter form
A typical filter form doesn't have a submit button, but every interaction with selects, checkboxes, radios etc immediately update the UI. It's convenient to have an
onChange
as proposed above to update the UI.