jaredpalmer/formik

Validate only one field at a time

Open

#512 创建于 2018年3月13日

在 GitHub 查看
 (131 评论) (199 反应) (0 负责人)TypeScript (34,255 star) (2,801 fork)batch import
Type: Enhancementhelp wanted

描述

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:

贡献者指南