Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
Conditional Validation in Yup Formik React

I am trying to add conditional validations for a field that exists is a part of one form but is not for the other.

This is my custom validation of yup.

export const validationSchema = Yup.object({
  id: Yup.string(),
  name: Yup.string().required('required'),
  level: Yup.object().when('$exist', {
    is: (exist) => exist,
    then: Yup.object().typeError('required').required('required'),
    otherwise: Yup.object(),
  }),
});

In the case where the field is not present it is working fine as it should be. But the validation doesn't work when the field actually exists in the Formik form it returns with an error

level must be a object type, but the field value was null. If "null" is intended as an empty value be sure to mark the schema as nullable()"

I want to make my "level" validation work for one case and not for the other

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda