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 * Create a new ComboCheck
15 * @param {Object} config Configuration options
17 Roo.form.ComboCheck = function(config){
18 Roo.form.ComboCheck.superclass.constructor.call(this, config);
19 // should verify some data...
21 // hiddenName = required..
22 // displayField = required
23 // valudField == required
24 var req= [ 'hiddenName', 'displayField', 'valueField' ];
26 Roo.each(req, function(e) {
27 if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
28 throw "Roo.form.ComboCheck : missing value for: " + e;
35 Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
40 selectedClass: 'x-menu-item-checked',
43 onRender : function(ct, position){
49 var cls = 'x-combo-list';
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>' +
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 this.pageTb.add(new Roo.Toolbar.Fill(), {
76 onViewOver : function(e, t){
82 onViewClick : function(doFocus,index){
87 Roo.log("SELECT CALLED");
94 if(!this.store.getCount()){
95 this.onEmptyResults();
99 this.restrictHeight();
102 if(!this.selectByValue(this.value, true)){
103 this.select(0, true);
110 selectByValue : function(xv, scrollIntoView){
111 var ar = this.getValueArray();
114 Roo.each(ar, function(v) {
115 if(v === undefined || v === null){
118 var r = this.findRecord(this.valueField, v);
120 sels.push(this.store.indexOf(r))
130 onSelect : function(record, index){
131 Roo.log("onselect Called");
132 // this is only called by the clear button now..
133 this.view.clearSelections();
135 getValueArray : function()
139 var ar = Roo.decode(this.value);
140 return ar instanceof Array ? ar : []; //?? valid?
143 Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
150 collapse : function(){
151 Roo.form.ComboCheck.superclass.collapse.call(this);
152 var sl = this.view.getSelectedIndexes();
157 Roo.each(sl, function(i) {
159 nv.push(r.get(this.valueField));
161 this.setValue(Roo.encode(nv))
165 setValue : function(v){
169 var vals = this.getValueArray();
171 Roo.each(vals, function(k) {
172 var r = this.findRecord(this.valueField, k);
174 tv.push(r.data[this.displayField]);
175 }else if(this.valueNotFoundText !== undefined){
176 tv.push( this.valueNotFoundText );
181 Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
182 this.hiddenField.value = v;