3 * Copyright(c) 2008-2011 Alan Knowles
10 * @class Roo.form.ComboCheck
11 * @extends Roo.form.ComboBox
12 * A combobox for multiple select items.
14 * FIXME - could do with a reset button..
17 * Create a new ComboCheck
18 * @param {Object} config Configuration options
20 Roo.form.ComboCheck = function(config){
21 Roo.form.ComboCheck.superclass.constructor.call(this, config);
22 // should verify some data...
24 // hiddenName = required..
25 // displayField = required
26 // valudField == required
27 var req= [ 'hiddenName', 'displayField', 'valueField' ];
29 Roo.each(req, function(e) {
30 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
31 throw "Roo.form.ComboCheck : missing value for: " + e;
38 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
43 selectedClass: 'x-menu-item-checked',
46 onRender : function(ct, position){
52 var cls = 'x-combo-list';
55 this.tpl = new Roo.Template({
56 html : '<div class="'+cls+'-item x-menu-check-item">' +
57 '<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
58 '<span>{' + this.displayField + '}</span>' +
65 Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
66 this.view.singleSelect = false;
67 this.view.multiSelect = true;
68 this.view.toggleSelect = true;
69 this.pageTb.add(new Roo.Toolbar.Fill(), {
79 onViewOver : function(e, t){
85 onViewClick : function(doFocus,index){
90 //Roo.log("SELECT CALLED");
93 selectByValue : function(xv, scrollIntoView){
94 var ar = this.getValueArray();
97 Roo.each(ar, function(v) {
98 if(v === undefined || v === null){
101 var r = this.findRecord(this.valueField, v);
103 sels.push(this.store.indexOf(r))
107 this.view.select(sels);
113 onSelect : function(record, index){
114 // Roo.log("onselect Called");
115 // this is only called by the clear button now..
116 this.view.clearSelections();
118 if (this.value != this.valueBefore) {
119 this.fireEvent('change', this, this.value, this.valueBefore);
120 this.valueBefore = this.value;
123 getValueArray : function()
128 //Roo.log(this.value);
129 if (typeof(this.value) == 'undefined') {
132 var ar = Roo.decode(this.value);
133 return ar instanceof Array ? ar : []; //?? valid?
136 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
144 Roo.form.ComboCheck.superclass.expand.call(this);
145 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
146 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
151 collapse : function(){
152 Roo.form.ComboCheck.superclass.collapse.call(this);
153 var sl = this.view.getSelectedIndexes();
158 Roo.each(sl, function(i) {
160 nv.push(r.get(this.valueField));
162 this.setValue(Roo.encode(nv));
163 if (this.value != this.valueBefore) {
165 this.fireEvent('change', this, this.value, this.valueBefore);
166 this.valueBefore = this.value;
171 setValue : function(v){
175 var vals = this.getValueArray();
177 Roo.each(vals, function(k) {
178 var r = this.findRecord(this.valueField, k);
180 tv.push(r.data[this.displayField]);
181 }else if(this.valueNotFoundText !== undefined){
182 tv.push( this.valueNotFoundText );
187 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
188 this.hiddenField.value = v;