@@ -212,6 +212,27 @@ component accessors="true" serialize="false" singleton {
212212 arguments .includeFields = arrayToList ( arguments .includeFields );
213213 }
214214
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+
215236 // iterate over constraints defined
216237 for ( var this Field in allConstraints ) {
217238 var validateField = true ;
@@ -304,7 +325,7 @@ component accessors="true" serialize="false" singleton {
304325 // process the incoming rules
305326 for ( var key in arguments .rules ) {
306327 // if message validators, just ignore
307- if ( reFindNoCase ( " Message$" , key ) ) {
328+ if ( reFindNoCase ( " Message$" , key ) || key == " defaultValue " ) {
308329 continue ;
309330 }
310331
@@ -507,4 +528,36 @@ component accessors="true" serialize="false" singleton {
507528 );
508529 }
509530
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+
510563}
0 commit comments