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

804
Visualizações
Vuelidate: Make field optional based on other checkbox (should apply to custom validations as well)

How to keep a field optional in Vuelidate?

Vuelidate gives $v in code. To check form validation we have $invalid prop Now how do I keep x field optional based on checkbox thing eg.

[ ] use y field
[ y text field ] (right now optional)

but if i check the checkbox

[x] use y field
[ y text field ] (now its required and it will follow other validations such as sameAs/minLength/max/custom validation

PS: It should also validate custom validations as well.

I have this jsfiddle. What I want is, If I check the is universal box then only validations should apply over the input box else the validations should be ignored and $invalid should be false

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you need to change your validations property to a function, this will let you to access state using this. also you need to check your checkbox value in your custom validators too:

validations() {
  return {
    text: {
        required: requiredIf(function () {
        return this.isUniversal
      }),
      roblox (val) {
        return this.isUniversal ? !!val.match(/roblox.com/) : true
      }
    }
  }
},

i edited your jsfiddle

over 4 years ago · Santiago Trujillo Relatório
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