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.

Get values in validationSchema for dynamic validation rules

See original GitHub issue

As well as accessing the props in validationSchema is it possible to get the current values? I’m wanting a way to define the validation dynamically based on the values selected by the user.

e.g.

validationSchema?: Schema | ((props: Props) => Schema)
// becomes
validationSchema?: Schema | ((values: Values, props: Props) => Schema)

happy to submit a PR if you’re interested in this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

115reactions
davetimminscommented, Aug 30, 2017

Yes it is thanks!

so if anyone is interested it’s now

validationSchema: props => {
    return Yup.lazy(values => {      
      return Yup.object().shape({

whereas before it was

validationSchema: props =>    
    Yup.object().shape({
7reactions
codeincontextcommented, Aug 30, 2017

Hi Dave

Is yup.lazy enough to solve your problem? https://github.com/jquense/yup/blob/master/README.md#yuplazyvalue-any--schema-lazy On Wed, 30 Aug 2017 at 00:23 Dave Timmins notifications@github.com wrote:

As well as accessing the props in validationSchema is it possible to get the current values? I’m wanting a way to define the validation dynamically based on the values selected by the user.

e.g.

validationSchema?: Schema | ((props: Props) => Schema)// becomes validationSchema?: Schema | ((values: Values, props: Props) => Schema)

happy to submit a PR if you’re interested in this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jaredpalmer/formik/issues/145, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFj60XxOsLDgusTVRG3AZ1eqX3_eHpIks5sdOPPgaJpZM4PG2Z2 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create an Optional Dynamic Validation Schema based ...
We'll be talking about run-time schema validation. Essentially this lets you define validation rules on the fly when you are attempting to validate...
Read more >
Dynamic validation with Yup and Formik using React hooks
In this lesson, I will show u how to deal with dynamic validation based on the article: How-to-Create-an-Optional-Dynamic-Validation-Schema- ...
Read more >
Create an Optional Dynamic Validation Schema ... - Egghead.io
In this lesson we'll show how to setup a nested validation structure using the yup library. We'll then use the yup.lazy method to...
Read more >
Yup / Formik validation using dynamic keys - Stack Overflow
I want to loop through my object and pass a dynamic set of keys to the schema - basically however long the object...
Read more >
Create an Optional Dynamic Validation Schema ... - YouTube
We'll then use the yup.lazy method to evaluate the value at runtime and adjust our validation schema. We'll make our nested validation ......
Read more >

github_iconTop Related Medium Post

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