@@ -212,6 +212,27 @@ component accessors="true" serialize="false" singleton {
212
212
arguments .includeFields = arrayToList ( arguments .includeFields );
213
213
}
214
214
215
+ // iterate over fields to apply default values
216
+ for ( var this Field in allConstraints ) {
217
+ /*
218
+ results = results,
219
+ rules = allConstraints[ thisField ],
220
+ target = arguments.target,
221
+ field = thisField,
222
+ locale = arguments.locale
223
+ */
224
+ if ( allConstraints [ this Field ].keyExists ( " defaultValue" ) ) {
225
+ var targetValue = invoke ( arguments .target , " get" & this Field );
226
+ if ( isNull ( targetValue ) || ! hasValue ( targetValue ) ) {
227
+ invoke (
228
+ arguments .target ,
229
+ " set" & this Field ,
230
+ [ allConstraints [ this Field ].defaultValue ]
231
+ );
232
+ }
233
+ }
234
+ }
235
+
215
236
// iterate over constraints defined
216
237
for ( var this Field in allConstraints ) {
217
238
var validateField = true ;
@@ -304,7 +325,7 @@ component accessors="true" serialize="false" singleton {
304
325
// process the incoming rules
305
326
for ( var key in arguments .rules ) {
306
327
// if message validators, just ignore
307
- if ( reFindNoCase ( " Message$" , key ) ) {
328
+ if ( reFindNoCase ( " Message$" , key ) || key == " defaultValue " ) {
308
329
continue ;
309
330
}
310
331
@@ -507,4 +528,36 @@ component accessors="true" serialize="false" singleton {
507
528
);
508
529
}
509
530
531
+ /**
532
+ * Verify if the target value has a value
533
+ * Checks for nullness or for length if it's a simple value, array, query, struct or object.
534
+ */
535
+ boolean function hasValue ( any targetValue ){
536
+ // Null Tests
537
+ if ( isNull ( arguments .targetValue ) ) {
538
+ return false ;
539
+ }
540
+ // Simple Tests
541
+ if ( isSimpleValue ( arguments .targetValue ) AND len ( trim ( arguments .targetValue ) ) ) {
542
+ return true ;
543
+ }
544
+ // Array Tests
545
+ if ( isArray ( arguments .targetValue ) and arrayLen ( arguments .targetValue ) ) {
546
+ return true ;
547
+ }
548
+ // Query Tests
549
+ if ( isQuery ( arguments .targetValue ) and arguments .targetValue .recordcount ) {
550
+ return true ;
551
+ }
552
+ // Struct Tests
553
+ if ( isStruct ( arguments .targetValue ) and structCount ( arguments .targetValue ) ) {
554
+ return true ;
555
+ }
556
+ // Object
557
+ if ( isObject ( arguments .targetValue ) ) {
558
+ return true ;
559
+ }
560
+ return false ;
561
+ }
562
+
510
563
}
0 commit comments