question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synchronous validation

See original GitHub issue

Bug, Feature, or Question?

Question

Current Behavior

Since Yup validations are async, components render twice as far as I’ve read in previous issues, and I have 150 input fields on one page and it’s extremely noticeable when user starts to type, it basically becomes unusable. So, since there is boolean flag in validateYupSchema method for synchronous version is there a way to set it as prop on Formik component?

Desired Behavior

To run Yup validations synchronously.


  • Formik Version: 1.0.0-alpha.2
  • React Version: 16.2.0
  • OS: MacOS
  • Node Version: 8.9.1
  • Package Manager and Version: npm v5.6.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
latviancodercommented, Mar 8, 2018

By the way, this is how I did synchronous validation using yup and validate function:

import { validateYupSchema, yupToFormErrors } from 'formik';

validate: (values: FormValues) => {
    const validationSchema = object().shape({
        ...
    });

    try {
        validateYupSchema<FormValues>(values, validationSchema, true);
    } catch (err) {
        return yupToFormErrors(err);
    }

    return {};
},
4reactions
pietmichalcommented, Feb 11, 2020

This is even more relevant now because async validation now triggers act errors in tests when using React Hooks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Synchronous Validation Example - Redux Form
IMPORTANT: Synchronous validation happens on every change to your form data, so, if your field value is invalid, your field.error value will always...
Read more >
Redux Form - Synchronous Validation - CodeSandbox
A synchronous validation example using Redux Form. 10. 34.9k. 2.4k. erikraserikras. Environmentcreate-react-app. Files. SyncValidationForm.js. index.js.
Read more >
Synchronization Validation - Informatica Documentation
You can validate run-time synchronization of dynamic sources and targets. If you configure a dynamic mapping that uses data sources that are set...
Read more >
Creating Angular Synchronous and Asynchronous Validators ...
Synchronous and asynchronous Validators are very similar - the main difference is that a sync Validator returns an error object instance ...
Read more >
Synchronous Validation for multiple messages.
Synchronous Validation for multiple messages. Description. During streaming Ingestion via HTTP API, synchronous Validation not working ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found