examples/form/nestedcombo.js
[roojs1] / examples / form / nestedcombo.js
1 /*
2  * 
3  * (C) Alan Knowles 2011
4  * Licence : Roojs - LGPL
5  */
6  
7 var mform;
8 var combo
9 Roo.onReady(function(){
10
11     Roo.QuickTips.init();
12
13       sampledata  = [
14         ['A', 'A states', [
15             ['AK', 'Alaska'],
16             ['AZ', 'Arizona'],
17             ['AR', 'Arkansas']
18                            
19         ]],
20         ['C', 'C states', [        
21           ['CA', 'California'],
22             ['CO', 'Colorado'],
23             ['CT', 'Connecticut']
24         ]],
25         ['D', 'D states', [
26             ['DE', 'Delaware'],
27             ['DC', 'District of Columbia']
28         ]],
29         ['I', 'I states', [
30         
31             ['ID', 'Idaho'],
32             ['IL', 'Illinois'],
33             ['IN', 'Indiana'],
34             ['IA', 'Iowa'],
35             ['IDA', 'Idaho'],
36             ['ILA', 'Illinois'],
37             ['INA', 'Indiana'],
38             ['IAA', 'Iowa']
39         ]],
40         ['E', 'Empty states', []],
41     ];
42     /*
43      * ================  Form 2  =======================
44      */
45     mform = Roo.factory({
46         xns : Roo.form,
47         xtype : 'Form',
48         labelAlign: 'top',
49         items : [
50             {
51                 xtype : 'ComboNested',
52                 xns: Roo.form,
53                 
54                 fieldLabel: 'State',
55                 
56                 name : 'states_list',
57                 hiddenName:'states',
58                 
59                 
60                 valueField : 'abbr',
61                 displayField:'state',
62                 
63              
64                 store: {
65                     xns : Roo.data,
66                     xtype : 'SimpleStore',
67                     fields: ['abbr', 'state' , 'cn'],
68                     data : sampledata// from states.js
69                    
70                 },
71                 listWidth: 400,
72                 typeAhead: true,
73                 mode: 'local',
74                 triggerAction: 'all',
75                 emptyText:'Select a state...',
76                 selectOnFocus:true,
77                 width:190,
78                 listeners : {
79                     change: function() {
80                         Roo.log("changed to " + this.getValue());
81                         
82                     }
83                 }
84           }
85
86             
87         ]
88         
89     });
90
91     mform.render('form-ct5');
92     combo = mform.findField('states');
93    /* mform.setValues({
94         states : '["AK","AZ"]',
95         states_list : "Alaska, Arizona"
96         
97     });
98     */
99     
100     
101 });