@@ -5,15 +5,14 @@ component {
55
66 // Index
77 any function index ( event , rc , prc ){
8-
98 // Test Mixins
109 log .info ( " validateHasValue #validateHasValue ( " true" ) # has passed!" );
1110 log .info ( " validateIsNullOrEmpty #validateIsNullOrEmpty ( " true" ) # has passed!" );
1211 assert ( true );
13- try {
12+ try {
1413 assert ( false , " bogus line" );
15- } catch ( AssertException e ){}
16- catch ( any e ){
14+ } catch ( AssertException e ) {
15+ } catch ( any e ) {
1716 rethrow ;
1817 }
1918
@@ -26,39 +25,29 @@ component {
2625 password : { required : true , size : " 6..20" }
2726 };
2827 // validation
29- validate (
30- target = rc ,
31- constraints = constraints
32- ).onError ( function ( results ){
33- flash .put (
34- " notice" ,
35- arguments .results .getAllErrors ().tostring ()
36- );
37- return index ( event , rc , prc );
38- })
39- .onSuccess ( function ( results ){
40- flash .put ( " notice" , " User info validated!" );
41- relocate ( " main" );
42- } )
28+ validate ( target = rc , constraints = constraints )
29+ .onError ( function ( results ){
30+ flash .put ( " notice" , arguments .results .getAllErrors ().tostring () );
31+ return index ( event , rc , prc );
32+ } )
33+ .onSuccess ( function ( results ){
34+ flash .put ( " notice" , " User info validated!" );
35+ relocate ( " main" );
36+ } )
4337 ;
4438 }
4539
4640 any function saveShared ( event , rc , prc ){
4741 // validation
48- validate (
49- target = rc ,
50- constraints = " sharedUser"
51- ).onError ( function ( results ){
52- flash .put (
53- " notice" ,
54- results .getAllErrors ().tostring ()
55- );
56- return index ( event , rc , prc );
57- })
58- .onSuccess ( function ( results ){
59- flash .put ( " User info validated!" );
60- setNextEvent ( " main" );
61- } );
42+ validate ( target = rc , constraints = " sharedUser" )
43+ .onError ( function ( results ){
44+ flash .put ( " notice" , results .getAllErrors ().tostring () );
45+ return index ( event , rc , prc );
46+ } )
47+ .onSuccess ( function ( results ){
48+ flash .put ( " User info validated!" );
49+ setNextEvent ( " main" );
50+ } );
6251 }
6352
6453 /**
@@ -71,10 +60,46 @@ component {
7160 };
7261
7362 // validate
74- prc .key s = validateOrFail (
75- target = rc ,
76- constraints = constraints
77- );
63+ prc .key s = validateOrFail ( target = rc , constraints = constraints );
64+
65+ return prc .key s ;
66+ }
67+
68+ /**
69+ * validateOrFailWithNestedKeys
70+ */
71+ function validateOrFailWithNestedKeys ( event , rc , prc ){
72+ var constraints = {
73+ " keep0" : { " required" : true , " type" : " string" },
74+ " keepNested0" : {
75+ " required" : true ,
76+ " type" : " struct" ,
77+ " constraints" : {
78+ " keepNested1" : {
79+ " required" : true ,
80+ " type" : " struct" ,
81+ " constraints" : { " keep2" : { " required" : true , " type" : " string" } }
82+ },
83+ " keepArray1" : {
84+ " required" : true ,
85+ " type" : " array" ,
86+ " items" : {
87+ " type" : " struct" ,
88+ " constraints" : { " keepNested3" : { " required" : true , " type" : " string" } }
89+ }
90+ },
91+ " keepArray1B" : {
92+ " required" : true ,
93+ " type" : " array" ,
94+ " items" : { " type" : " array" , " arrayItem" : { " type" : " string" } }
95+ }
96+ }
97+ },
98+ " keepNested0B.keep1B" : { " required" : true , " type" : " string" }
99+ };
100+
101+ // validate
102+ prc .key s = validateOrFail ( target = rc , constraints = constraints );
78103
79104 return prc .key s ;
80105 }
@@ -98,27 +123,22 @@ component {
98123 var oModel = populateModel ( " User" );
99124
100125 // validate
101- prc .object = validateOrFail (
102- target = oModel ,
103- profiles = rc ._profiles
104- );
126+ prc .object = validateOrFail ( target = oModel , profiles = rc ._profiles );
105127
106128 return " Validated" ;
107- }
108-
109-
110- /**
129+ }
130+
131+
132+ /**
111133 * validateOnly
112134 */
113- function validateOnly ( event , rc , prc ){
114-
115- var oModel = populateModel ( " User" );
135+ function validateOnly ( event , rc , prc ){
136+ var oModel = populateModel ( " User" );
116137
117138 // validate
118- prc .result = validate ( oModel );
139+ prc .result = validate ( oModel );
119140
120141 return " Validated" ;
121-
122142 }
123143
124144
0 commit comments