Search code examples
vue.jsvuejs2vuelidate

Custom validation with Vuelidate Vuejs


I have 4 inputs, all must be required( witch I did, and works), but first input must be equal with the next 3 fields, witch is not working with my current code. (also I get no error in console)

import { required, minValue } from "vuelidate/lib/validators";
// ..code...
created() {
    const minValue = (value) => value === this.high_confidence + this.medium_confidence + this.no_confidence;
},

validations: {
    nr_of_clauses_per_round: {
        required,
        minValue
    },
    high_confidence: {
        required
    },
    medium_confidence: {
        required
    },
    no_confidence: {
        required
    }
},

Solution

  • You should import { sameAs } from Vuelidate too, and add a validation sameAs([your field]), like that.

    Please read the doc: https://vuelidate.js.org/#sub-contextified-validators