1

I try to do a simple maxValue, but I am not sure how can I use a value from vue data. URL for package.

import { required, maxValue } from "vuelidate/lib/validators";

export default {
  data() {
    return {
      totalClauses: 10,
    };
  },
  validations: {
    nr_of_clauses: {
      required,
      maxValue: maxValue(this.totalClauses)
    },
  },
}
1
  • No, it doesn't belong. Is nothing fancy here, just a variable from vuejs "totalClauses" that I want to use in validations (I will edit the post with package URL). Right now I get error when I try to use it in maxValue. Commented Jun 4, 2020 at 13:13

2 Answers 2

1

Validations schema can be a function, which will make it dynamic and possibly dependant on your model's data. [source]

So,

import { required, maxValue } from "vuelidate/lib/validators";

export default {
  data() {
    return {
      totalClauses: 10,
    };
  },

  validations() {
    return {
      nr_of_clauses: {
        required,
        maxValue: maxValue(this.totalClauses)
      },
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

I know that the answer for this issue was found, but i want to quickly recommend changing from Vuelidate to VeeValidate. I've used both and Vuelidate has some limitations that VeeValidate solves like custom validations(with messages for each validation) and it's more simple to use.

You can find Veevalidate documentation here

1 Comment

Cool, I heard about it, but I didn't tried. With first opportunity I will try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.