0

below my code.

For some reason, the iscountrycode is undefined when I put it into the .when. in the console.log the result is 'BE'

export function getCheckoutFormSchema(t?: any, iscountryCode?: string) {`
    console.log(iscountryCode)`
    let schema = Yup.object().shape({`
       zip: Yup.string()
            .when(iscountryCode, {
                is: 'BE',
                then: Yup.string()`

Does anybody know why this is happening?

Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
Bert
  • 3
  • 2

1 Answers1

1

I think you forgot to apply quotes ('') around iscountryCode field.

Try this -

let schema = Yup.object().shape({ 
   zip: Yup.string().when('iscountryCode', { is: 'BE', then: Yup.string()...}
)

also one more point you need to fact check -

  • your schema must have this field you are using 'iscountryCode',
    let schema = Yup.object().shape({ 
    iscountryCode: Yup.string(),
    zip: Yup.string().when('iscountryCode', { is: 'BE', then: Yup.string()...}
    

)

both fields should be at the sibling level.