async-validator
async-validator copied to clipboard
the parameter of validator 'source' is not origin value
I use 'validator' to define rule myself, I expect the forth parameter of validator 'source' is what I passed, but it is the deeper object of what I passed. like
const desc = {
person1: {
type: 'object',
fields: {
age: {
validator(rule, value, callback, source, options) {
console.log(source);
if (value > source.person2.age2) {
return callback('need less than 0');
}
return callback();
}
}
}
}
};
const validator = new Schema(desc);
validator.validate({ person1: { age: 1, sex: 1, name: '1' }, person2: { age: 2, sex: 2, name: '2' } }, { firstFields: true });
I expect 'source' is { person1: { age: 1, sex: 1, name: '1' }, person2: { age: 2, sex: 2, name: '2' } }, but I get { age: 1, sex: 1, name: '1' }. Is there any way to control 'source' ?
@firewithwind 你找到解决办法了吗?