Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

803
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!