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 object array length check array in object validation check at the same time ?

See original GitHub issue

Describe the bug how object array length check array in object validation check at the same time ?

To Reproduce

https://codesandbox.io/s/elegant-darwin-23lch

i use yup react-hook-form. but yup validation scheme only check array length. not array in object validation check don’t work my object schema under

 const schema = yup
    .array()
    .min(1)
    .max(3)
    .of(
      yup.object().shape({
        optionName: yup
          .string()
          .required()
          .trim()
          .min(0)
          .max(100),
        optionPrice: yup
          .number()
          .required()
          .min(1000)
          .max(500000)
      })
    );

  const obj = [
    { optionName: "test", optionPrice: 0 },
    { optionName: "", optionPrice: 0 }
  ];
  await expect(schema.isValid(obj)).resolves.toBe(true);

Expected behavior A clear and concise description of what you expected to happen.

Platform (please complete the following information):

  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jquensecommented, Mar 11, 2020
const obj = [
    { optionName: "test", optionPrice: 0 },
    { optionName: "test1", optionPrice: 0 },
{ optionName: "test2", optionPrice: 0 },
{ optionName: "test3", optionPrice: 0 },
  ];
  await expect(schema.isValid(obj)).resolves.toBe(true);

this will never be true, because optionPrice has a min set. If you don’t want validation on the items, don’t add validation to them

0reactions
ghostcommented, Mar 12, 2020

ok thank you haha i will close issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation using Yup to check array length - Stack Overflow
Now I check the name is required, I need to check if myArray has length === 1 to return an error. javascript ·...
Read more >
Find the length of a JavaScript object - GeeksforGeeks
Method 1: Using the Object.keys() method. The Object.keys() method is used to return the object property name as an array. The length ......
Read more >
Find duplicates in an array using javaScript - Flexiple
1. We compare the index of all the items of an array with the index of the first time that number occurs. If...
Read more >
How to check if an array is empty using Javascript? - Flexiple
If the length of the object is 0, then the array is considered to be empty and the function will return TRUE. Else...
Read more >
JavaScript Array length Property - W3Schools
Definition and Usage. The length property sets or returns the number of elements in an array. Syntax. Return the length of an array:....
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