How to Use Vuelidate With Conditional Validation
1 min read

How to Use Vuelidate With Conditional Validation

How to Use Vuelidate With Conditional Validation

I was building a form with Vue and Vuelidate.
My goal was to pass a prop that would turn a field into a required field.
Vuelidate has a validator `requiredIf` which can make the field optionally or conditionally required.

prop: {
	active: {
    	type: Boolean,
        default: true
    }
},
validations: {
  field: {
    required: requiredIf(function (field) {
      return this.active
    })
  }
}