Formik: [0.8] Validation Options Config API

Created on 17 Jul 2017  路  2Comments  路  Source: formium/formik

Current Behavior
Formik validates only during onChange events

Desired Behavior
As a user of the library, I'd like to be able to configure whether validation runs during onChange or onBlur events and their respective imperative functions ( setFieldValue and setFieldTouched).

Ideas:

// Single option
export interface FormikConfig<Props, Values, Payload> {
  ...
  /** 
   *   Tells Formik to validate the form on each input's onChange 
   *   event INSTEAD of the onBlur event 
   */
  validateOnChange?: boolean;
}
// Two options
export interface FormikConfig<Props, Values, Payload> {
  ...
  /** 
   *   Tells Formik to validate the form on each input's onChange 
   *   event. Default is `false`
   */
  validateOnChange?: boolean;
  /** 
   *   Tells Formik to validate the form on each input's onBlur
   *   event. Default is `true`
   */
  validateOnBlur?: boolean;
}

Most helpful comment

I'm a fan of option 2. More flexible, including offering the option to turn off both change and blur validation, which option 1 doesn't support.

All 2 comments

I'm a fan of option 2. More flexible, including offering the option to turn off both change and blur validation, which option 1 doesn't support.

Much agreed, Option 2 looks like the better option. I just started using Formik, which I love, but validating only onChange can provide a poor user experience, especially when evaluating required fields.

Was this page helpful?
0 / 5 - 0 ratings