Search code examples
vue.jsvee-validate

Vee validate multiple validation


I've created custom rule using extend from vee-validate. so i've this rules

required|numeric|min_value:1|lte:@max_quantity|lte:@stock

from above code when lte:@max_quantity is false and lte:@stock is true it get override by the last rule so the result always considered as true instead of false

so how can i achieve this?

rules:

extend("gte", {
  params: ["target"],
  validate(value, { target }) {
    return value >= target;
  },
  message: "{_field_} greater than or equal to {target}"
});

extend("lte", {
  params: ["target"],
  validate(value, { target }) {
    return value <= target;
  },
  message: "{_field_} less than or equal to {target}"
});

Solution

  • To handle this you could create a custom rule that accepts multiple arguments @max_quantity and @stock, and computes the result taking both into consideration. Then specify that custom rule name instead of lte.