Configuration File
Shared Constraints
You can optionally register constraints in your ColdBox configuration file under the validation directive. This means you register them with a unique name of your choice and its value is a collection of constraints for fields in your objects or forms. These will be called lovingly Shared Constraints.
Here is an example:

Declaration

config/ColdBox.cfc
1
validation = {
2
sharedConstraints = {
3
sharedUser = {
4
fName = {required=true},
5
lname = {required=true},
6
age = {required=true, max=18 }
7
metadata = {required=false, type="json"}
8
},
9
loginForm = {
10
username = {required=true}, password = {required=true}
11
},
12
changePasswordForm = {
13
password = {required=true,min=6}, password2 = {required=true, sameAs="password", min=6}
14
}
15
}
16
}
Copied!
As you can see, our constraints definition describes the set of rules for a property on ANY target object or form by unique key name.

Usage

You can then use the keys for those constraints in the validation calls:
1
validate( target, "sharedUser" );
2
3
validate( rc, "loginForm" );
4
5
validate( rc, "changePasswordForm" );
Copied!
Last modified 1yr ago
Copy link