examples/form/dynamic.js
[roojs1] / examples / form / dynamic.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12 var mform;
13 var simple;
14
15 Roo.onReady(function(){
16
17     Roo.QuickTips.init();
18
19     // turn on validation errors beside the field globally
20     Roo.form.Field.prototype.msgTarget = 'side';
21
22     /*
23      * ================  Simple form  =======================
24      */
25     simple = new Roo.form.Form({
26         labelWidth: 75, // label settings here cascade unless overridden
27         url:'save-form.php'
28     });
29     simple.add(
30         new Roo.form.TextField({
31             fieldLabel: 'First Name',
32             name: 'first',
33             width:175,
34             allowBlank:false
35         }),
36
37         new Roo.form.TextField({
38             fieldLabel: 'Last Name',
39             name: 'last',
40             width:175
41         }),
42
43         new Roo.form.TextField({
44             fieldLabel: 'Company',
45             name: 'company',
46             width:175
47         }),
48         new Roo.form.TextField({
49             fieldLabel: 'Password',
50             name: 'pwd',
51             inputType: 'password',
52             width:175
53         }),
54
55         new Roo.form.TextField({
56             fieldLabel: 'Email',
57             name: 'email',
58             vtype:'email',
59             width:175
60         }),
61          new Roo.form.DayPicker({
62             fieldLabel: 'Pick a day',
63             name: 'daypick',
64             width:175
65         })
66     );
67
68     simple.addButton('Save');
69     simple.addButton('Cancel');
70
71     simple.render('form-ct');
72
73
74     /*
75      * ================  Form 2  =======================
76      */
77     mform = new Roo.form.Form({
78         labelAlign: 'top',
79         items : [
80             
81             {
82                 
83                 xtype : 'Column', 
84                 width: 500, // precise column sizes or percentages or straight CSS
85                 items : [
86                     {
87                         xtype : 'ComboBoxArray',
88                         xns : Roo.form,
89                         fieldLabel: 'Multi select test',
90                         name: 'countryNames',
91                         hiddenName: 'country',
92                         
93                         width: 550,
94                         combo : {
95                             
96                             valueField : 'abbr',
97                             displayField : 'state',
98                             
99                             name : 'countryNames',
100                             hiddenName : 'country',
101                             
102                             xtype : 'ComboBox',
103                             xns : Roo.form,
104                             store: {
105                                 xtype : 'SimpleStore',
106                                 xns: Roo.data,
107                                 fields: ['abbr', 'state'],
108                                 data : Roo.exampledata.states // from states.js    
109                             },
110                             width: 200,
111                             listWidth : 300,
112                             editable : false,
113                             
114                             typeAhead: false,
115                             mode: 'local',
116                             triggerAction: 'all',
117                             emptyText:'Select a state...',
118                             selectOnFocus:true,
119                             resizable:true
120                         }
121                         
122                         
123                     }
124                     
125                 ]
126             },
127             
128             
129             {
130                 
131                 xtype : 'Column', 
132                 width: 500, // precise column sizes or percentages or straight CSS
133                 items : [
134                     {
135                         xtype : 'ComboBoxArray',
136                         xns : Roo.form,
137                         fieldLabel: 'Multi select test',
138                         
139                         
140                         name: 'countrylist_names',
141                         hiddenName: 'countrylist',
142                         
143                         width: 550,
144                         combo : {
145                             
146                             valueField : 'code',
147                             displayField : 'title',
148                             
149                             // thes are not really needed as parent overwrites them!?
150                             name : 'country_name',
151                             hiddenName : 'country',
152                             
153                             xtype : 'ComboBox',
154                             xns : Roo.form,
155                             
156                             
157                              
158         
159                             
160                             store: {
161                                 xtype : 'Store',
162                                 xns: Roo.data,
163                                 
164                                 proxy: {
165                                     xns : Roo.data,
166                                     xtype : 'ScriptTagProxy',
167                                     url: 'http://www.roojs.com/forum/topics-remote.php'
168                                 },
169                                 reader: {
170                                     xns : Roo.data,
171                                     xtype : 'JsonReader',
172                                     root: 'topics',
173                                     totalProperty: 'totalCount',
174                                     id: 'post_id',
175                                     fields : [
176                                         {name: 'title', mapping: 'topic_title'},
177                                         {name: 'topicId', mapping: 'topic_id'},
178                                         {name: 'author', mapping: 'author'},
179                                         {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
180                                         {name: 'excerpt', mapping: 'post_text'}
181                                     ]
182                                 }
183                             },
184                             width: 200,
185                             listWidth : 300,
186                             editable : false,
187                             
188                             typeAhead: false,
189                             mode: 'local',
190                             triggerAction: 'all',
191                             emptyText:'Select a state...',
192                             selectOnFocus:true,
193                             resizable:true
194                         }
195                         
196                         
197                     }
198                     
199                 ]
200             },
201             
202            
203
204             
205             
206             
207             {
208                 
209                 xtype : 'Column', 
210                 width: 272, // precise column sizes or percentages or straight CSS
211                 items : [
212                     {
213                         xtype : 'TextField',
214                         fieldLabel: 'First Name',
215                         name: 'first',
216                         width:225
217                     },
218                     {
219                         xtype : 'TextField',
220                         fieldLabel: 'Company',
221                         name: 'company',
222                         width:225
223                     }
224                 ]
225             },
226     
227             {
228                 xtype : 'Column', 
229                 width:272, 
230                 style:'margin-left:10px', 
231                 clear:true,
232                 items : [
233                     {
234                         xtype : 'TextField',
235                         fieldLabel: 'Last Name',
236                         name: 'last',
237                         width:225
238                     },
239                     {
240                         xtype : 'TextField',
241                         fieldLabel: 'Email',
242                         name: 'email',
243                         vtype:'email',
244                         width:225
245                     }
246                 ]
247             },  
248             {
249                   
250                 xtype : 'Column', 
251                 width:600, 
252                 labelAlign: 'top',
253                 items : [
254                     {
255                         xtype : 'HtmlEditor',
256                         name : 'bio',
257                         fieldLabel:'Biography',
258                         width:550,
259                         height:200,
260                         resizable: 's' /// where the handles should got..
261                     }
262                 ]
263             }
264         ] 
265        
266     });
267     mform.addButton('Save');
268     mform.addButton('Cancel');
269
270    
271     mform.render('form-ct2');
272     mform.setValues({
273         country  : 'AK,LA',
274         countryNames : 'Alaska,Louisana',
275         countrylist  : 'AG,AZ',
276         countrylist_names : 'Antigua and Barbuda,Azerbaijan'        
277     });
278     /*
279      * ================  Form 3  =======================
280      */
281     var fs = new Roo.form.Form({
282         labelAlign: 'right',
283         labelWidth: 80
284     });
285
286     fs.fieldset(
287         {legend:'Contact Information', style: 'width:320px;' },
288         new Roo.form.TextField({
289             fieldLabel: 'First Name',
290             name: 'first',
291             width:190
292         }),
293
294         new Roo.form.TextField({
295             fieldLabel: 'Last Name',
296             name: 'last',
297             width:190
298         }),
299
300         new Roo.form.TextField({
301             fieldLabel: 'Company',
302             name: 'company',
303             width:190
304         }),
305
306         new Roo.form.TextField({
307             fieldLabel: 'Email',
308             name: 'email',
309             vtype:'email',
310             width:190
311         }),
312
313         new Roo.form.ComboBox({
314             fieldLabel: 'State',
315             hiddenName:'state',
316             store: new Roo.data.SimpleStore({
317                 fields: ['abbr', 'state'],
318                 data : Roo.exampledata.states // from states.js
319             }),
320             displayField:'state',
321             typeAhead: true,
322             mode: 'local',
323             triggerAction: 'all',
324             emptyText:'Select a state...',
325             selectOnFocus:true,
326             width:190
327         }),
328
329         new Roo.form.DateField({
330             fieldLabel: 'Date of Birth',
331             name: 'dob',
332             width:190,
333             allowBlank:false
334         }),
335         new Roo.form.MonthField({
336             fieldLabel: 'Date of Month',
337             name: 'dom',
338             width:190,
339             allowBlank:false
340         })
341     );
342
343     fs.addButton('Save');
344     fs.addButton('Cancel');
345
346     fs.render('form-ct3');
347
348     /*
349      * ================  Form 4  =======================
350      */
351     var form = new Roo.form.Form({
352         labelAlign: 'right',
353         labelWidth: 75
354     });
355
356     form.column({width:342, labelWidth:75}); // open column, without auto close
357     form.fieldset(
358         {legend:'Contact Information'},
359         new Roo.form.TextField({
360             fieldLabel: 'Full Name',
361             name: 'fullName',
362             allowBlank:false,
363             value: 'Fred Blogs'
364         }),
365
366         new Roo.form.TextField({
367             fieldLabel: 'Job Title',
368             name: 'title',
369             value: 'RooJS user'
370         }),
371
372         new Roo.form.TextField({
373             fieldLabel: 'Company',
374             name: 'company',
375             value: 'RooJS'
376         }),
377
378         new Roo.form.TextArea({
379             fieldLabel: 'Address',
380             name: 'address',
381             grow: true,
382             preventScrollbars:true,
383             value: '123 example drive'
384         })
385     );
386     form.fieldset(
387         {legend:'Phone Numbers'},
388         new Roo.form.TextField({
389             fieldLabel: 'Home',
390             name: 'home',
391             value: '(123) 456 789'
392         }),
393
394         new Roo.form.TextField({
395             fieldLabel: 'Business',
396             name: 'business'
397         }),
398
399         new Roo.form.TextField({
400             fieldLabel: 'Mobile',
401             name: 'mobile'
402         }),
403
404         new Roo.form.TextField({
405             fieldLabel: 'Fax',
406             name: 'fax'
407         })
408     );
409     form.end(); // closes the last container element (column, layout, fieldset, etc) and moves up 1 level in the stack
410
411     
412     form.column(
413         {width:202, style:'margin-left:10px', clear:true}
414     );
415
416     form.fieldset(
417         {id:'photo', legend:'Photo'}
418     );
419     form.end();
420
421     form.fieldset(
422         {legend:'Options', hideLabels:true},
423         new Roo.form.Checkbox({
424             boxLabel:'RooJS v1.1.1',
425             name:'extuser',
426             width:'auto'
427         }),
428         new Roo.form.Checkbox({
429             boxLabel:'RooJS v2.0.0',
430             name:'extcomm',
431             width:'auto'
432         }),
433         new Roo.form.Checkbox({
434             boxLabel:'RooScript',
435             name:'extprem',
436             width:'auto'
437         })
438         
439     );
440
441     form.end(); // close the column
442
443     
444     form.applyIfToFields({
445         width:230
446     });
447
448     form.addButton('Save');
449     form.addButton('Cancel');
450
451     form.render('form-ct4');
452
453     // The form elements are standard HTML elements. By assigning an id (as we did above)
454     // we can manipulate them like any other element
455     var photo = Roo.get('photo');
456     var c = photo.createChild({
457         tag:'center', 
458         cn: {
459             tag:'img',
460             src: 'roojs_icon.jpg',
461             style:'margin-bottom:5px;'
462         }
463     });
464     new Roo.Button(c, {
465         text: 'Change Photo'
466     });
467     
468    form5 = new Roo.form.Form({
469         labelAlign: 'left',
470         labelWidth: 120,
471         items : [
472             {
473             
474                 xtype: 'Checkbox',
475                 xns : Roo.form,
476                fieldLabel: 'A checkbox',
477                 boxLabel:'RooJS v1.1.1',
478                 name:'extuser',
479                 inputValue : '1',
480                 value : '1',
481                 width:'auto'
482             },
483             {
484                 xtype : 'DisplayField',
485                 xns : Roo.form,
486                 name:'textex',
487                 fieldLabel: 'Simple',
488                 value : 'example text'
489             } ,
490             {
491                 xtype: 'ComboBox',
492                 xns : Roo.form,
493                 fieldLabel: 'State',
494                 hiddenName:'state',
495                 store: {
496                     xtype: 'SimpleStore',
497                     xns : Roo.data,
498                     fields: ['abbr', 'state'],
499                     data : Roo.exampledata.states // from states.js
500                 },
501                 displayField:'state',
502                 typeAhead: true,
503                 mode: 'local',
504                 triggerAction: 'all',
505                 emptyText:'Select a state...',
506                 selectOnFocus:true,
507                 width:190,
508                 listeners : {
509                     add : function()
510                     {
511                         Roo.MessageBox.alert("Alert", "Add Pressed");
512                     },
513                     edit : function()
514                     {
515                         Roo.MessageBox.alert("Alert", "Edit Pressed");
516                     }
517                     
518                 }
519             },
520         
521         ]
522     });
523     
524     form5.render('form-ct5');
525  
526     
527     form6 = new Roo.form.Form({
528         labelAlign: 'left',
529         labelWidth: 120,
530         items : [
531             {
532             
533                 xtype: 'TimePicker',
534                 xns : Roo.form,
535                 fieldLabel: 'test time picker',
536                 name: 'time'
537             },
538             {
539                 xtype: 'DateDisplay',
540                 xns : Roo.form,
541                 fieldLabel: 'test date picker',
542                 name: 'date'
543             }
544              
545         
546         ]
547     });
548     
549     form6.render('form-ct6');
550  
551     
552     
553     
554 });