examples/bootstrap/ComboBox.js
[roojs1] / examples / bootstrap / ComboBox.js
1
2
3 Roo.example = Roo.example || {};
4
5 Roo.example.combobox = new Roo.XComponent({
6     part     :  ["layout","viewpanel"],
7     order    : '001-viewpanel',
8     region   : '',
9     parent   : '#bootstrap',
10     name     : "unnamed module",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         
16         this.parent = {
17             el : new Roo.bootstrap.Body()
18         }
19         this.parent.el.layout = false;
20         this.parent.el.render(document.body);
21         
22         var _this = this;
23         var MODULE = this;
24         var baseURL = '/web.eventmanager/demo.local.php';
25         
26         return {
27             xtype: 'Body',
28             xns: Roo.bootstrap,
29             items : [
30                  {
31                     xtype: 'ComboBox',
32                     xns: Roo.bootstrap,
33                     placeholder : 'Select a country',
34                     displayField : 'name',
35                     hiddenName : 'country_id',
36                     md : '12',
37                     size : 'sm',
38                     name : 'country_id_name',
39                     triggerAction : 'all',
40                     minChars : '1',
41                     tpl : '<li class="select2-result"><b>{name}</b></div>',
42                     listWidth : '400',
43                     multiple: true,
44                     listeners : {
45                         render : function (_self) {
46                             _this.countrySel = _self;
47                         }
48                     },
49                     forceSelection : true,
50                     valueField : 'id',
51                     queryParam : 'query[name]',
52                     editable : true,
53                     alwaysQuery : true,
54                     allowBlank : false,
55                     fieldLabel : 'Country',
56                     pageSize : '10',
57                     append: true,
58                     store : {
59                         xtype: 'Store',
60                         xns: Roo.data,
61                         listeners : {
62                             beforeload : function (_self, o) {
63                                 o.params = o.params || {};
64                                 
65                                 var selected = _this.countrySel.getValue();
66                                 
67                                 if(selected.length){
68                                     Roo.log(selected);
69                                 }
70                             }
71                         },
72                         remoteSort : true,
73                         sortInfo : { direction : 'ASC', field: 'name' },
74                         proxy : {
75                             xtype: 'HttpProxy',
76                             xns: Roo.data,
77                             url : baseURL + '/Roo/Core_geoip_country',
78                             method : 'GET'
79                         },
80                         reader : {
81                             xtype: 'JsonReader',
82                             xns: Roo.data,
83                             fields : [
84                                 {
85                                     'name': 'id',
86                                     'type': 'int'
87                                 },
88                                 {
89                                     'name': 'code',
90                                     'type': 'string'
91                                 },
92                                 {
93                                     'name': 'name',
94                                     'type': 'string'
95                                 }
96                             ]
97                         }
98                     }
99                 }
100             ]
101         };
102     }
103 });