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.

How to require either one of two fields? (Cyclic dependency error)

See original GitHub issue

What (if possible) is the correct way to define that either the email or phone is a string > 1?

    var formModelSchema = yup.object({
        email: yup.string().email().when('phone', {
            is: (phone) => !phone || phone.length === 0,
            then: yup.string().email().required(),
            otherwise: yup.string()
        }),
        phone: yup.string().when('email', {
            is: (email) => !email || email.length === 0,
            then: yup.string().required(),
            otherwise: yup.string()
        })
    });

Uncaught (in promise) Error: Cyclic dependency: "phone"

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:28
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

116reactions
GeoffreyHervetcommented, Sep 27, 2020
    var formModelSchema = yup.object({
        email: yup.string().email().when('phone', {
            is: (phone) => !phone || phone.length === 0,
            then: yup.string().email().required(),
            otherwise: yup.string()
        }),
        phone: yup.string().when('email', {
            is: (email) => !email || email.length === 0,
            then: yup.string().required(),
            otherwise: yup.string()
        })
    },
   // This is what you missed
   [ [ 'email', 'phone' ] ]
);
20reactions
Qwalcommented, Oct 7, 2020

I had to use yup.object().shape({...}) with @GeoffreyHervet solution to avoid cyclic dependency error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Yup validate either one of two fields is required (one of them is ...
You can achieve this by creating a type that is interdepedent on related_items_id and short_desc export interface BaseType { title: string; ...
Read more >
yup: Conditional Validation & Cyclic Dependency Error Fix
You have 3 fields in a form: is_mobile_app , ios_id and android_id . If is_mobile_app is false, then both ios_id and android_id both...
Read more >
How to validate two fields that depend on each other with Yup
Solution: const yup = require('yup') const { setLocale } = yup setLocale({ mixed: { notType: 'the ${path} is obligatory', required: 'the field ......
Read more >
How to fix the “Circular dependency detected” error in Google ...
The "Circular dependency detected" error in Google Sheets, is a very common error that can occur when using almost any formula.
Read more >
Avoiding circular dependency errors in DAX - SQLBI
If your code looks correct, that is if you do not see any obvious circular dependencies, then there are two possible causes for...
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