-
Notifications
You must be signed in to change notification settings - Fork 94
Closed
Description
Hello,
Thank you for this open source project. I use fastest-validator on my websites.
I found an issue about the custom validator.
The result of the custom validator lost a property field
.
<script src="https://unpkg.com/fastest-validator"></script>
let v = new FastestValidator({
messages: {
// Register our new error message text
weightMin: "The weight must be greater than {expected}! Actual: {actual}"
}
});
const schema = {
name: { type: "string", min: 3, max: 255 },
weight: {
type: "custom",
minWeight: 10,
check(value, schema) {
return (value < schema.minWeight)
? [{ type: "weightMin", expected: schema.minWeight, actual: value }]
: true;
}
}
};
console.log(v.validate({ name: "John", weight: 8 }, schema));
[
{
"message": "The weight must be greater than 10! Actual: 8",
"type": "weightMin",
"expected": 10,
"actual": 8
}
]
It should be:
[
{
"message": "The weight must be greater than 10! Actual: 8",
"type": "weightMin",
"expected": 10,
"field": "weight",
"actual": 8
}
]
Metadata
Metadata
Assignees
Labels
No labels