async-validator icon indicating copy to clipboard operation
async-validator copied to clipboard

the parameter of validator 'source' is not origin value

Open firewithwind opened this issue 6 years ago • 2 comments

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 avatar Aug 01 '19 12:08 firewithwind

@firewithwind 你找到解决办法了吗?

AlwaysNoobCoder avatar Feb 01 '24 07:02 AlwaysNoobCoder