Closed akan01n closed 3 weeks ago
After some tests. I added a 'otherwise' clause and the function is called inside the otherwise. So "optsA" is always "false".
Is it because optsB is nested and "when" can't see the parent optsA ??
The solution I found so far is to move optsA inside optsB.
const optsFormSchema = yup.object({
optsB: yup.object({
optsA: yup.boolean().required(),
list: yup
.array()
.of(yup.number())
.when([
"optsA",
{
is: true,
then: (schema) => schema.isArraySorted(),
},
]),
}),
});
I found others solutions, but in my case I am using react-hooks-form and I can't reference 'context' to add to Yup validator.
Describe the bug I created a new method using the 'addMethod' function, but when I try to use this new method with 'when' inside the 'then' clause, the function is not called. But if I use this new function without 'when' clause, it works.
To Reproduce
Just simple code with example to show the problem.
Working Schema 'isArraySorted' is called
NOT working Schema 'isArraySorted' not called
Expected behavior The custom function created with 'addMethod' to work inside 'when' clause.
Platform (please complete the following information):
Additional context The point here is to check if the custom method added with 'addMethod' is being called inside the 'then' clause.
Thanks :)