14
14
min-height : 1400px ;
15
15
}
16
16
17
+ .alert .form-group {
18
+ margin-bottom : 0px ;
19
+ }
20
+
17
21
.red {
18
22
border : 1px solid red;
19
23
background : # fee ;
@@ -31,12 +35,19 @@ <h1>Schema Form Example</h1>
31
35
< div class ="row ">
32
36
< div class ="col-sm-4 ">
33
37
< h3 > The Generated Form</ h3 >
34
- < form name ="ngform " sf-model ="person " sf-form ="form " sf-schema ="schema " sf-decorator ="{{decorator}} ">
38
+ < form name ="ngform " sf-model ="modelData " sf-form ="form " sf-schema ="schema " sf-decorator ="{{decorator}} ">
35
39
</ form >
36
40
< h3 > Model</ h3 >
37
41
< pre ng-cloak > {{pretty()}}</ pre >
38
42
</ div >
39
43
< div class ="col-sm-8 ">
44
+ < h3 > Select Example</ h3 >
45
+ < div class ="form-group ">
46
+ < select class ="form-control " id ="selectTest "
47
+ ng-model ="selectedTest "
48
+ ng-options ="obj.name for obj in tests ">
49
+ </ select >
50
+ </ div >
40
51
< h3 > Form</ h3 >
41
52
< div ui-ace ="{ theme: 'monokai',mode:'json'} "
42
53
ng-class ="{red: !itParsesForm} " ng-model ="formJson " class ="form-control form "> </ div >
@@ -64,212 +75,34 @@ <h3>Schema</h3>
64
75
65
76
angular . module ( 'test' , [ 'schemaForm' , 'ui.ace' ] ) ;
66
77
67
- function TestCtrl ( $scope ) {
68
- $scope . person = {
69
- favorite : 'NaN' ,
70
- arraytest2 : [ "foo" , "bar" , "foo" ]
71
- } ;
78
+ function TestCtrl ( $scope , $http ) {
72
79
73
- $scope . schema = {
74
- "type" : "object" ,
75
- "required" : [ 'name' , 'shoesize' ] ,
76
- "properties" : {
77
- "arraytest" : {
78
- "title" : "arraytest" ,
79
- "type" : "array" ,
80
- "items" : {
81
- "type" : "object" ,
82
- "title" : "Names" ,
83
- "properties" : {
84
- "name" : { "type" : "string" , "title" : "Your name" } ,
85
- "nick" : { "type" : "string" , "title" : "Your nick" , "default" : "Yo!" } ,
86
- }
87
- }
88
- } ,
89
- "arraytest2" : {
90
- "title" : "arraytest 2" ,
91
- "type" : "array" ,
92
- "items" : {
93
- "type" : "string" ,
94
- "title" : "Name"
95
- }
96
- } ,
97
- "arraytest3" : {
98
- "title" : "arraytest 3" ,
99
- "type" : "array" ,
100
- "items" : {
101
- "type" : "object" ,
102
- "title" : "Cool list" ,
103
- "properties" : {
104
- "name" : { "title" : "sublist name" , "type" : "string" } ,
105
- "sublist" : {
106
- "type" : "array" ,
107
- "items" : {
108
- "title" : "sublist value" , "type" : "string"
109
- }
110
- }
111
- }
112
- }
113
- } ,
80
+ $scope . tests = [
81
+ { name : "Simple" , data : 'data/simple.json' } ,
82
+ { name : "Array" , data : 'data/array.json' } ,
83
+ { name : "Tab Array" , data : 'data/tabarray.json' } ,
84
+ { name : "Kitchen Sink" , data : 'data/sink.json' }
85
+ ] ;
114
86
115
- "name" : {
116
- "title" : "Name" ,
117
- "description" : "Gimme yea name lad" ,
118
- "type" : "string" ,
119
- "pattern" : "^[^/]*$" ,
120
- "minLength" : 2
121
- } ,
122
- "favorite" : {
123
- "title" : "Favorite" ,
124
- "type" : "string" ,
125
- "enum" : [
126
- "undefined" ,
127
- "null" ,
128
- "NaN" ,
129
- ]
130
- } ,
131
- "shoesize" : {
132
- "title" : "Shoe size" ,
133
- "default" : 42 ,
134
- "type" : "number" ,
135
- } ,
136
- "attributes" : {
137
- "type" : "object" ,
138
- "title" : "Attributes" ,
139
- "required" : [ 'eyecolor' ] ,
140
- "properties" : {
141
- "eyecolor" : { "type" : "string" , "title" : "Eye color" } ,
142
- "haircolor" : { "type" : "string" , "title" : "Hair color" } ,
143
- "shoulders" : {
144
- "type" : "object" ,
145
- "title" : "Shoulders" ,
146
- "properties" : {
147
- "left" : { "type" : "string" , "title" : "Left" } ,
148
- "right" : { "type" : "string" , "title" : "Right" } ,
149
- }
150
- }
151
- }
152
- } ,
153
- "things" : {
154
- "type" : "array" ,
155
- "title" : "I like..." ,
156
- "items" : {
157
- "type" : "string" ,
158
- "enum" : [
159
- "clowns" , "compiling" , "sleeping"
160
- ]
161
- }
162
- } ,
163
- "soul" : {
164
- "title" : "Terms Of Service" ,
165
- "description" : "I agree to sell my undying <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>soul</a>" ,
166
- "type" : "boolean" ,
167
- "default" : true ,
168
- } ,
169
- "soulserial" : {
170
- "title" : "Soul Serial No" ,
171
- "type" : "string"
172
- } ,
173
- "date" : {
174
- "title" : "Date of party" ,
175
- "type" : "string" ,
176
- "format" : "date"
177
- } ,
178
- "radio" : {
179
- "type" :"string" ,
180
- "enum" : [ "Transistor" , "Tube" ]
181
- } ,
182
- "radiobuttons" : {
183
- "type" :"string" ,
184
- "enum" : [ "Select me!" , "No me!" ]
185
- }
87
+ $scope . selectedTest = $scope . tests [ 0 ] ;
88
+
89
+ $scope . $watch ( 'selectedTest' , function ( val ) {
90
+ if ( val ) {
91
+ $http . get ( val . data ) . then ( function ( res ) {
92
+ $scope . schema = res . data . schema ;
93
+ $scope . form = res . data . form ;
94
+ $scope . schemaJson = JSON . stringify ( $scope . schema , undefined , 2 ) ;
95
+ $scope . formJson = JSON . stringify ( $scope . form , undefined , 2 ) ;
96
+ $scope . modelData = res . data . model || { } ;
97
+ } ) ;
186
98
}
187
- } ;
188
-
189
- $scope . form = [
190
- {
191
- title : "value.name || 'Tab '+$index" ,
192
- key : "arraytest" ,
193
- type : "tabarray" ,
194
- items : [
195
- "arraytest[].nick" ,
196
- "arraytest[].name"
197
- ]
198
- } ,
199
- "arraytest2" ,
200
- "arraytest3" ,
201
- {
202
- type : "fieldset" ,
203
- title : "Stuff" ,
204
- items : [
205
- {
206
- type : "tabs" ,
207
- tabs : [
208
- {
209
- title : "Simple stuff" ,
210
- items : [
211
- {
212
- key : "name" ,
213
- placeholder : "Check the console" ,
214
- onChange : "log(modelValue)" ,
215
- feedback : "{'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-star': !hasSuccess() }"
216
- } ,
217
- {
218
- key : "favorite" ,
219
- feedback : false
220
- }
221
- ]
222
- } ,
223
- {
224
- title : "More stuff" ,
225
- items : [
226
- "attributes" ,
227
- {
228
- key : "shoesize" ,
229
- feedback : false
230
- } ,
231
- "things"
232
- ]
233
- } ]
234
- } ,
235
- ]
236
- } ,
237
- {
238
- type : "help" ,
239
- helpvalue : "<hr>"
240
- } ,
241
- "soul" ,
242
- {
243
- type : "conditional" ,
244
- condition : "person.soul" ,
245
- items : [
246
- { key : "soulserial" , placeholder : "ex. 666" }
247
- ]
248
- } ,
249
- { key : "date" , minDate : "2014-06-20" } ,
250
- { key : "radio" ,
251
- type : "radios" ,
252
- titleMap : {
253
- "Transistor" : "Transistor <br> Not the tube kind." ,
254
- "Tube" : "Tube <br> The tube kind."
255
- }
256
- } ,
257
- { key : "radiobuttons" , type : "radiobuttons" } ,
258
- {
259
- type : 'actions' ,
260
- items : [
261
- { type : 'submit' , title : 'Do It!' } ,
262
- { type : 'button' , title : 'Noooooooooooo' , onClick : 'sayNo()' }
263
- ]
264
- }
265
- ] ;
99
+ } ) ;
266
100
267
101
$scope . decorator = 'bootstrap-decorator' ;
268
102
269
103
$scope . itParses = true ;
270
104
$scope . itParsesForm = true ;
271
- $scope . schemaJson = JSON . stringify ( $scope . schema , undefined , 2 ) ;
272
- $scope . formJson = JSON . stringify ( $scope . form , undefined , 2 ) ;
105
+
273
106
274
107
$scope . $watch ( 'schemaJson' , function ( val , old ) {
275
108
if ( val && val !== old ) {
@@ -293,9 +126,8 @@ <h3>Schema</h3>
293
126
}
294
127
} ) ;
295
128
296
-
297
129
$scope . pretty = function ( ) {
298
- return JSON . stringify ( $scope . person , undefined , 2 , 2 ) ;
130
+ return JSON . stringify ( $scope . modelData , undefined , 2 , 2 ) ;
299
131
} ;
300
132
301
133
$scope . log = function ( msg ) {
@@ -306,6 +138,10 @@ <h3>Schema</h3>
306
138
alert ( 'Noooooooo' ) ;
307
139
} ;
308
140
141
+ $scope . say = function ( msg ) {
142
+ alert ( msg ) ;
143
+ } ;
144
+
309
145
}
310
146
311
147
</ script >
0 commit comments