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

310
Visualizações
How to run validation only if element exists? Formik+Yup

I'm using Formik+Yup for creating a form and validation. My form is multipage and it has next-button, which should be disabled until all required fields are filled up correctly(with no validation error). Everything was pretty simple(I was just using validateOnMount and disabling button just with !formik.isValid) until I came to the page with radio buttons which should pop up another question(also with radio buttons) depending on your answer on previous question.

If I use validateOnMount all validations run (even questions that would not pop up) so it is impossible to activate the button. Using validateOnBlur or OnChange also did not work for same reason. I found the solution only by writing really long and hard 'if' statemen which looks like this

disabled={
!formik.values.covidStatus ||
(formik.values.covidStatus === 'covidYes' && !formik.values.igTest) ||
(formik.values.covidStatus === 'covidYes' && formik.values.igTest === 'IgYes' &&
(!formik.values.testDate || !formik.values.igNumber)) || 
(formik.values.covidStatus === 'covidYes' && formik.values.igTest === 'IgNo' &&
 !formik.values.covidDate) 
}

I tried to write custom validation for radio questions and question is: Is it possible to determine when custom validation will run? To be precise I want that validation to run only when field exists.

about 4 years ago · Juan Pablo Isaza
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