jaredpalmer/formik

Validate only one field at a time

Open

#512 opened on Mar 13, 2018

View on GitHub
 (131 comments) (199 reactions) (0 assignees)TypeScript (34,255 stars) (2,801 forks)batch import
Type: Enhancementhelp wanted

Description

Bug, Feature, or Question?

Feature/Question

Current Behavior

Currently, validation is running asynchronously on the whole schema (assuming you use ValidationSchema of yup). It is reasonable to run the validation on submit, however, It is extremely cumbersome to run it on every field change/blur.

Especially if you have some backend validation (using yup.test). Assuming you have a couple of fields, field A, and field B - the later must go through backend validation. Every time you change field A, the validation runs both on A and B which will cause unnecessary backend calls.

I also tried using the new alpha version's handleChange('fieldName') but I still experience the same behavior.

Suggested Solutions

  1. Using yup schema, using yup.reach seems reasonable, even though I'm not sure how is its performance (https://github.com/jaredpalmer/formik/issues/35)

  2. Formik validate function - pass the event's field name. It will allow the developer to validate only one field at a time.

Environment

  • Formik Version: 0.11.11 /1.0.0-alpha.2
  • React Version: 16.2
  • TypeScript Version: 2.7.2
  • CodeSandbox Link:
  • OS: macOS High Sierra
  • Node Version: 8.9.4
  • Package Manager and Version:

Contributor guide