Skip to content

Commit 0f36c57

Browse files
committed
Merge branch 'development' of github.com:coldbox-modules/cbox-validation into development
2 parents 902cdc3 + c7d6c46 commit 0f36c57

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

modules/cbvalidation/models/IValidationManager.cfc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ interface{
1616
* @constraints.hint An optional shared constraints name or an actual structure of constraints to validate on.
1717
* @locale.hint An optional locale to use for i18n messages
1818
* @excludeFields.hint An optional list of fields to exclude from the validation.
19+
* @includeFields.hint An optional list of fields to include in the validation.
1920
*/
20-
IValidationResult function validate(required any target, string fields, any constraints, string locale="", string excludeFields="");
21+
IValidationResult function validate( required any target, string fields, any constraints, string locale="", string excludeFields="", string includeFields="" );
2122

2223
/**
2324
* Retrieve the shared constraints

modules/cbvalidation/models/Mixins.cfm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* @fields The fields to validate on the target. By default, it validates on all fields
77
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
88
* @locale The i18n locale to use for validation messages
9-
* @excludeFields The fields to exclude in the validation
9+
* @excludeFields The fields to exclude from the validation
10+
* @includeFields The fields to include in the validation
1011
*
1112
* @return cbvalidation.model.result.IValidationResult
1213
*/
@@ -16,6 +17,7 @@ function validateModel(
1617
any constraints,
1718
string locale="",
1819
string excludeFields=""
20+
string includeFields=""
1921
){
2022
return getValidationManager().validate( argumentCollection=arguments );
2123
}

modules/cbvalidation/models/ValidationManager.cfc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ component accessors="true" serialize="false" implements="IValidationManager" sin
8989
* @constraints.hint An optional shared constraints name or an actual structure of constraints to validate on.
9090
* @locale.hint An optional locale to use for i18n messages
9191
* @excludeFields.hint An optional list of fields to exclude from the validation.
92+
* @IncludeFields.hint An optional list of fields to include in the validation.
9293
*/
93-
IValidationResult function validate(required any target, string fields="*", any constraints="", string locale="", string excludeFields=""){
94+
IValidationResult function validate( required any target, string fields="*", any constraints="", string locale="", string excludeFields="", string includeFields="" ){
9495
var targetName = "";
9596

9697
// Do we have a real object or a structure?
@@ -119,15 +120,23 @@ component accessors="true" serialize="false" implements="IValidationManager" sin
119120
// iterate over constraints defined
120121
var thisField = "";
121122
for( thisField in allConstraints ){
123+
124+
var validateField = true;
125+
if( len( arguments.includeFields ) AND NOT listFindNoCase( arguments.includeFields, thisField ) ){
126+
validateField = false;
127+
}
122128
// exclusions passed and field is in the excluded list just continue
123129
if( len( arguments.excludeFields ) and listFindNoCase( arguments.excludeFields, thisField ) ){
124-
continue;
130+
validateField = false;
125131
}
126-
// verify we can validate the field described in the constraint
127-
if( arguments.fields == "*" || listFindNoCase(arguments.fields, thisField) ) {
128-
// process the validation rules on the target field using the constraint validation data
129-
processRules(results=results, rules=allConstraints[thisField], target=arguments.target, field=thisField, locale=arguments.locale);
132+
if( validateField ){
133+
// verify we can validate the field described in the constraint
134+
if( arguments.fields == "*" || listFindNoCase( arguments.fields, thisField ) ) {
135+
// process the validation rules on the target field using the constraint validation data
136+
processRules( results=results, rules=allConstraints[ thisField ], target=arguments.target, field=thisField, locale=arguments.locale );
137+
}
130138
}
139+
131140
}
132141

133142
return results;
@@ -141,7 +150,7 @@ component accessors="true" serialize="false" implements="IValidationManager" sin
141150
for( var key in arguments.rules ){
142151
// if message validators, just ignore
143152
if( reFindNoCase( "Message$", key ) ){ continue; }
144-
153+
145154
// had to use nasty evaluate until adobe cf get's their act together on invoke.
146155
getValidator( validatorType=key, validationData=arguments.rules[ key ] )
147156
.validate(

0 commit comments

Comments
 (0)