Reputation: 665
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}"
});
Upvotes: 1
Views: 1457
Reputation: 7553
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
.
Upvotes: 1