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