Beusebiu
Beusebiu

Reputation: 1513

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
    }
},

Upvotes: 0

Views: 2467

Answers (1)

Etienne Bender
Etienne Bender

Reputation: 356

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

Upvotes: 1

Related Questions