Roo/form/ComboCheck.js
[roojs1] / Roo / form / ComboCheck.js
1 /*
2  * RooJS Library 1.1.1
3  * Copyright(c) 2008-2011  Alan Knowles
4  *
5  * License - LGPL
6  */
7  
8
9 /**
10  * @class Roo.form.ComboCheck
11  * @extends Roo.form.ComboBox
12  * A combobox for multiple select items.
13  * @constructor
14  * Create a new ComboCheck
15  * @param {Object} config Configuration options
16  */
17 Roo.form.ComboCheck = function(config){
18     Roo.form.ComboCheck.superclass.constructor.call(this, config);
19     // should verify some data...
20     // like
21     // hiddenName = required..
22     // displayField = required
23     // valudField == required
24     var req= [ 'hiddenName', 'displayField', 'valueField' ];
25     var _t = this;
26     Roo.each(req, function(e) {
27         if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
28             throw "Roo.form.ComboCheck : missing value for: " + e;
29         }
30     })
31     
32    
33 };
34
35 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
36      
37      
38     editable : false,
39      
40     selectedClass: 'x-menu-item-checked', 
41     
42     // private
43     onRender : function(ct, position){
44         var _t = this;
45         
46         
47         
48         if(!this.tpl){
49             var cls = 'x-combo-list';
50
51             
52             this.tpl =  new Roo.Template({
53                 html :  '<div class="'+cls+'-item x-menu-check-item">' +
54                    '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' + 
55                    '<span>{' + this.displayField + '}</span>' +
56                     '</div>' 
57                 
58             });
59         }
60  
61         
62         Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
63         this.view.singleSelect = false;
64         this.view.multiSelect = true;
65         this.view.toggleSelect = true;
66     },
67     
68     onViewOver : function(e, t){
69         // do nothing...
70         return;
71         
72     },
73     
74     onViewClick : function(doFocus,index){
75         return;
76         
77     },
78     select: function () {
79         
80     },
81     
82     onSelect : function(record, index){
83        // this is only called by the clear button now..
84        this.view.clearSelections();
85     },
86     getValueArray : function()
87     {
88         var ar = [] ;
89         try {
90             var ret = Roo.decode(thist.getValue());
91             ret = typeof(ar) == 'Array' ? ar : []; //?? valid?
92             return ret;
93         } catch(e) {
94             Roo.log("Roo.form.ComboCheck:getValueArray  invalid data:" + this.getValue());
95             return [];
96         }
97          
98     },
99     
100     
101     collapse : function(){
102         Roo.form.ComboCheck.superclass.collapse.call(this);
103         var sl = this.view.getSelectedIndexes();
104         var st = this.store;
105         var nv = [];
106         var tv = [];
107         var r;
108         Roo.each(sl, function(i) {
109             r = st.getAt(i);
110             nv.push(r.get(this.valueField));
111             tv.push(r.get(this.displayField));
112         },this);
113         
114         this.hiddenField.value = Roo.encode(nv);
115         
116         Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
117     },
118     
119     
120 });