Closed drastus closed 7 months ago
you are getting the wrong resolve
function in your test, b/c you are using an arrow function, this
in there refers the this
from the checkPhoneNumberString
function which is the string schema instance. Switch from an arrow function to a function expression and try again
I'm trying to write a custom Yup method for phone number validation. I have a separate field for phone number prefix (calling code), so I have to use it in my method.
Here is the outline of the custom method:
Is there any way to dereference other fields in
addMethod
?I know I can use
this.parent
in schema definition, but I'm using phone validation in a number of forms, so repeating the sametest
function over and over is not really a solution in my case.Test case: https://codesandbox.io/p/sandbox/polished-sea-2twzhf