Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing validation for FastFields #1007

Open
klis87 opened this issue Oct 15, 2018 · 6 comments · Fixed by #2749
Open

Optimizing validation for FastFields #1007

klis87 opened this issue Oct 15, 2018 · 6 comments · Fixed by #2749
Labels

Comments

@klis87
Copy link
Contributor

klis87 commented Oct 15, 2018

🚀 Feature request

Current Behavior

Currently FastField does rendering optimization, but still its onChange handler triggers validation for the whole validationSchema, which can be costly for really huge forms.

Desired Behavior

It would be perfect if onChange and onBlur of FastField could validate only slice of validationSchema

Suggested Solution

yup.reach is the answer - https://github.com/jquense/yup#yupreachschema-schema-path-string-value-object-context-object-schema Fast fields could call a new Formik method, which validates only schema corresponding to a given FastField. For instance, <FastField name="someName.nested" /> could do schema.reach('someName.nested') and use this for validation instead of validating the whole schema. Then, the validation result could be merger with Formik errors.

Who does this impact? Who is this for?

All users caring for the best possible form performance, who use Formik together with Yup, especially for big forms.

Describe alternatives you've considered

I have really big dynamic forms, sometimes +100 fields and I tried FastField - it is better now but for such a big form it is Yup which becomes a bottleneck - each key stroke validates 100+ fields, which could be especially costly for more expensive validators.

Alternatively I could use Field level validation, but I really like to keep validation logic only in yup, it is easy to test then and also it nicely keep good separation between yup and formik. Also, I dont like to repeat myself defining initialValue and schema.cast() does this automatically form me (provided I have all fields defined inside schema, not as field validators)

Additional context

N/A

@koyta
Copy link

koyta commented Nov 1, 2018

Big +, because i have same problems, validating causing much performance issues in big forms

@mschipperheyn
Copy link

Why don't you set validateOnBlur and validateOnChange={false}?

@klis87
Copy link
Contributor Author

klis87 commented Nov 2, 2018

@mschipperheyn no, because we dont want to turn of validation, we still wanna validate a given fast field, but not the whole yup schema on each key stroke

@klis87 klis87 mentioned this issue Nov 2, 2018
@klis87 klis87 mentioned this issue Dec 10, 2018
24 tasks
@stale
Copy link

stale bot commented Jan 1, 2019

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

@stale stale bot added the stale label Jan 1, 2019
@klis87
Copy link
Contributor Author

klis87 commented Jan 2, 2019

smoke signal

@jglesner
Copy link

jglesner commented Feb 2, 2020

+1. I had to do validateOnBlur and validateOnChange={false} to overcome this problem; however, validating only on blur negatively impacts the user experience because the user is required to click off or go to a different field. If there's an issue at that point, the user then needs to come back to the previous field and this is annoying to users. I would prefer for each field to only validate itself as @klis87 suggests so that (1) using Formik/Yup on large forms is performant, and (2) to provide the most real-time validation possible to users.

@stale stale bot removed the stale label Feb 2, 2020
@stale stale bot added the stale label Apr 2, 2020
@jaredpalmer jaredpalmer mentioned this issue Nov 10, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants