Validators
list
- class validator utils
- class validator rules
usage
class Test {
@IsNotEmpty()
name: string;
@IsNotEmpty()
@Max(50)
age: number;
}
const form = new Form(new Test());
// ❌
await form.validate(); // false
form.rawErrors; // { name: ['Is not empty'], age: ['Is not empty', 'age must be greater than 50'] }
// ❌
form.setDataProperty('name', 'Jhon Doe');
form.setDataProperty('age', 60);
await form.validate(); // false
form.rawErrors; // { age: ['age must be greater than 50'] }
// ✅
form.setDataProperty('age', 37);
await form.validate(); // true