How to use vuelidate to validate a Vue form with a conditional prop?

How to use vuelidate to validate a Vue form with a conditional prop?

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 required.

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