yiminghe / async-validator

validate form asynchronous
MIT License
8.88k stars 764 forks source link

多层嵌套对象验证规则怎么写? #323

Open J1angyue opened 1 year ago

J1angyue commented 1 year ago

比如有以下对象,要验证c属性: { a: { b: { c: 'ccc' } } } 规则是这样写吗?不生效啊 a: { type: 'object', required: true, fields: { b: { type: 'object', required: true, fields: { c: { type: 'string', required: true } } } } }

jswxwxf commented 1 year ago

Same issue

AllenYu0118 commented 1 year ago

@jswxwxf @J1angyue 我这边写是没问题的,试试参考这个最小实现,https://stackblitz.com/edit/typescript-7dtq2r?file=nest.ts

BoBoooooo commented 1 year ago

请问是否支持 这样的嵌套path定义?

const rules = {
  'a.b.c': [
    { required: true, message: 'a.b.c is required' },
    { type: 'string', message: 'a.b.c must be a string' },
  ],
};

const data = {
    a: {
        b: {
            c: '123'
        }
    }
}