Require at least one set of data in array to require all fields
See original GitHub issueHi There,
Im currently attempting to validate an array of this object shape:
export const exampleDataType = yup.object().shape({
email: yup.string().email("Email must be valid"),
phone: yup.string(),
name: yup.string(),
});
with the only condition being that at least one element of the array has to require all of the fields in the above object, but not all of the elements.
Example:
VALID:
[{
email: "",
phone: "1234",
name: "name"
},
{
email: "yup@email.com",
phone: "1234",
name: "yup"
}]
INVALID
[{
email: "",
phone: "1234",
name: "name"
},
{
email: "yup@email.com",
phone: "",
name: "yup"
}]
I’ve set up a basic sandbox, but without any real attempt to recreate as all my attemps have been absolute messes and can’t get them to work.
https://codesandbox.io/s/cranky-feistel-ozwuy?file=/src/index.test.js
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Is it possible to require at least one field from a set of defined ...
If you really don't care which one is required then you could just ensure there is at least one key in the object...
Read more >How to specify require for at least one of two elements? #180
My Schema has two array elements (recurring_schedule and specific_date) and I want to have at least one of them (both can also exist)...
Read more >Chapter 7: Arrays - cs.utsa.edu
An array is an object that stores many values of the same type. ... This will require passing a String as a parameter...
Read more >Data Structures: Objects and Arrays - Eloquent JavaScript
Many types of information require more than one atom, though. Objects allow us to group values—including other objects—to build more complex structures.
Read more >How to Require One Symfony Form Field and/or Another
The core of the forms component is a set of abstractions for handling form data in general, but actually doesn't do much. Almost...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
right, scratch what i said.
.isValidSync()
should donot quite, the return value of the functions is still a promise, async/await just makes async stuff look synchronous, it doesn’t actually make it sync, code receiving the value needs to expect and handle a promise