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(),{
84 cleanLeadingSpace : function(e)
86 // this is disabled, as it retriggers setvalue on blur
89 doForce : function() {
90 // no idea what this did, but it blanks out our values.
93 onViewOver : function(e, t){
99 onViewClick : function(doFocus,index){
103 select: function () {
104 //Roo.log("SELECT CALLED");
107 selectByValue : function(xv, scrollIntoView){
108 var ar = this.getValueArray();
111 Roo.each(ar, function(v) {
112 if(v === undefined || v === null){
115 var r = this.findRecord(this.valueField, v);
117 sels.push(this.store.indexOf(r))
121 this.view.select(sels);
125 selectAll : function()
128 this.store.each(function(r,i) {
131 this.view.select(sels);
137 onSelect : function(record, index){
138 // Roo.log("onselect Called");
139 // this is only called by the clear button now..
140 this.view.clearSelections();
142 if (this.value != this.valueBefore) {
143 this.fireEvent('change', this, this.value, this.valueBefore);
144 this.valueBefore = this.value;
147 getValueArray : function()
152 //Roo.log(this.value);
153 if (typeof(this.value) == 'undefined') {
156 var ar = Roo.decode(this.value);
157 return ar instanceof Array ? ar : []; //?? valid?
160 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
168 Roo.form.ComboCheck.superclass.expand.call(this);
169 this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
170 //this.valueBefore = typeof(this.valueBefore) == 'undefined' ? '' : this.valueBefore;
175 collapse : function(){
176 Roo.form.ComboCheck.superclass.collapse.call(this);
177 var sl = this.view.getSelectedIndexes();
182 Roo.each(sl, function(i) {
184 nv.push(r.get(this.valueField));
186 this.setValue(Roo.encode(nv));
187 if (this.value != this.valueBefore) {
189 this.fireEvent('change', this, this.value, this.valueBefore);
190 this.valueBefore = this.value;
195 setValue : function(v){
199 var vals = this.getValueArray();
201 Roo.each(vals, function(k) {
202 var r = this.findRecord(this.valueField, k);
204 tv.push(r.data[this.displayField]);
205 }else if(this.valueNotFoundText !== undefined){
206 tv.push( this.valueNotFoundText );
211 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
212 this.hiddenField.value = v;