Formik: [Feature] Add formikBag to validator

Created on 17 Jan 2018  路  4Comments  路  Source: formium/formik

Current Behavior

The validation handler function is not called with formikBag

Desired Behavior

Call validation function handler with formikBag

validate(values, formikBag)
This helps to allow passing results from the validation function back into the form i.e. through setStatus

Most helpful comment

Yea, in my validator, I perform a complex calculation from inputs as part of the form validation process. I understand that it would cause side effects, but it would be nice to have a way to pass the results of calculations since the operation is expensive and I do not want to repeat the operation outside of formik.

All 4 comments

This would encourage side effects in validation within Formik which is a bad practice. I鈥檓 not sure why you want to pass back results into the form as they are already available everywhere thru errors.

One reason could be to set a loading indicator via setStatus.
I would like to run certain rules (sync) on onChange, and other rules (sync+async) onBlur (and set a loading indicator while the async rules are loading).

With access to FormikBag or parts of the FormikBag, this would be possible and very simple to do - without causing to much side effects.

Yea, in my validator, I perform a complex calculation from inputs as part of the form validation process. I understand that it would cause side effects, but it would be nice to have a way to pass the results of calculations since the operation is expensive and I do not want to repeat the operation outside of formik.

I too would like to setStatus in the validate function!!! you can eventually just do it in submit handler, or if you really want to on a custom onChange/onBlur for a field where it has access.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jucesr picture Jucesr  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

PeerHartmann picture PeerHartmann  路  3Comments

pmonty picture pmonty  路  3Comments

sibelius picture sibelius  路  3Comments