Can you somehow create a .test that can have access to the initial value for a given field
For example an async "is email available" validation where the initial email value should be considered valid
const schema = Yup.object({
email: Yup.string()
.test('isAvailableAsync', 'The provided email is not available', async function (newValue) {
// with alias the value is undefined
// const initial = this.parent.emailInitial;
const initial = this.parent.initialEmailRef; // it's always the same with `newValue`
// email unchanged no need to do async call
if (newValue == initial) return true;
const result = await myAsyncCheck(email);
return result.exists == false;
})
initialEmailRef: Yup.ref('email'), // tried with ref
})
.from('email', 'emailInitial', true) // tried with alias