Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

792
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda