Validatable Delegate
Using the Validatable delegate for object validation
Overview
Basic Setup
Shorthand Syntax
class delegates="Validatable@cbValidation" {
property name="id" type="numeric";
property name="name" type="string";
property name="email" type="string";
this.constraints = {
name: { required: true, size: "2..100" },
email: { required: true, type: "email" }
};
}component delegates="Validatable@cbValidation" {
property name="id" type="numeric";
property name="name" type="string";
property name="email" type="string";
this.constraints = {
name = { required = true, size = "2..100" },
email = { required = true, type = "email" }
};
}Selective Method Delegation
Long Syntax with Property Injection
Available Delegated Methods
Using Delegated Validation Methods
Validate Method
ValidateOrFail Method
IsValid Method
Advanced Usage
Validation with Profiles
Custom Validation with Callbacks
Best Practices
1. Use Shorthand for Full Delegation
2. Use Selective Delegation for Lightweight Objects
3. Always Define Constraints
4. Use isValid() for Simple Checks
5. Use validateOrFail() for APIs
6. Combine with Custom Methods
Supported ColdBox Versions
See Also
Last updated
Was this helpful?