Skip to content

Commit 5279ff4

Browse files
committed
Added includeFields to the validate to match the populateModel options
1 parent 45292f1 commit 5279ff4

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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
99
* @excludeFields The fields to exclude in 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: 18 additions & 8 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 exclude from 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;
@@ -140,7 +149,9 @@ component accessors="true" serialize="false" implements="IValidationManager" sin
140149
// process the incoming rules
141150
for( var key in arguments.rules ){
142151
// if message validators, just ignore
143-
if( reFindNoCase( "Message$", key ) ){ continue; }
152+
if( reFindNoCase( "^(#replace( variables.validValidators, ",", "|", "all" )#)Message$", key ) ){ continue; }
153+
// if not in list, ignore
154+
if( !listFindNoCase( variables.validValidators, key ) ){ continue; }
144155

145156
// had to use nasty evaluate until adobe cf get's their act together on invoke.
146157
getValidator( validatorType=key, validationData=arguments.rules[ key ] )
@@ -179,7 +190,6 @@ component accessors="true" serialize="false" implements="IValidationManager" sin
179190
return wirebox.getInstance( arguments.validationData );
180191
}
181192
default : {
182-
if ( wirebox.getBinder().mappingExists( validatorType ) ) { return wirebox.getInstance( validatorType ); }
183193
throw(message="The validator you requested #arguments.validatorType# is not a valid validator",type="ValidationManager.InvalidValidatorType");
184194
}
185195
}

0 commit comments

Comments
 (0)