Roo/bootstrap/ComboBox.js
[roojs1] / Roo / bootstrap / ComboBox.js
1 /*
2  * - LGPL
3  * * 
4  */
5
6 /**
7  * @class Roo.bootstrap.ComboBox
8  * @extends Roo.bootstrap.TriggerField
9  * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10  * @cfg {Boolean} append (true|false) default false
11  * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12  * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13  * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14  * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15  * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16  * @cfg {Boolean} animate default true
17  * @cfg {Boolean} emptyResultText only for touch device
18  * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
19  * @constructor
20  * Create a new ComboBox.
21  * @param {Object} config Configuration options
22  */
23 Roo.bootstrap.ComboBox = function(config){
24     Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
25     this.addEvents({
26         /**
27          * @event expand
28          * Fires when the dropdown list is expanded
29              * @param {Roo.bootstrap.ComboBox} combo This combo box
30              */
31         'expand' : true,
32         /**
33          * @event collapse
34          * Fires when the dropdown list is collapsed
35              * @param {Roo.bootstrap.ComboBox} combo This combo box
36              */
37         'collapse' : true,
38         /**
39          * @event beforeselect
40          * Fires before a list item is selected. Return false to cancel the selection.
41              * @param {Roo.bootstrap.ComboBox} combo This combo box
42              * @param {Roo.data.Record} record The data record returned from the underlying store
43              * @param {Number} index The index of the selected item in the dropdown list
44              */
45         'beforeselect' : true,
46         /**
47          * @event select
48          * Fires when a list item is selected
49              * @param {Roo.bootstrap.ComboBox} combo This combo box
50              * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
51              * @param {Number} index The index of the selected item in the dropdown list
52              */
53         'select' : true,
54         /**
55          * @event beforequery
56          * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
57          * The event object passed has these properties:
58              * @param {Roo.bootstrap.ComboBox} combo This combo box
59              * @param {String} query The query
60              * @param {Boolean} forceAll true to force "all" query
61              * @param {Boolean} cancel true to cancel the query
62              * @param {Object} e The query event object
63              */
64         'beforequery': true,
65          /**
66          * @event add
67          * Fires when the 'add' icon is pressed (add a listener to enable add button)
68              * @param {Roo.bootstrap.ComboBox} combo This combo box
69              */
70         'add' : true,
71         /**
72          * @event edit
73          * Fires when the 'edit' icon is pressed (add a listener to enable add button)
74              * @param {Roo.bootstrap.ComboBox} combo This combo box
75              * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
76              */
77         'edit' : true,
78         /**
79          * @event remove
80          * Fires when the remove value from the combobox array
81              * @param {Roo.bootstrap.ComboBox} combo This combo box
82              */
83         'remove' : true,
84         /**
85          * @event specialfilter
86          * Fires when specialfilter
87             * @param {Roo.bootstrap.ComboBox} combo This combo box
88             */
89         'specialfilter' : true,
90         /**
91          * @event tick
92          * Fires when tick the element
93             * @param {Roo.bootstrap.ComboBox} combo This combo box
94             */
95         'tick' : true
96         
97     });
98     
99     this.item = [];
100     this.tickItems = [];
101     
102     this.selectedIndex = -1;
103     if(this.mode == 'local'){
104         if(config.queryDelay === undefined){
105             this.queryDelay = 10;
106         }
107         if(config.minChars === undefined){
108             this.minChars = 0;
109         }
110     }
111 };
112
113 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
114      
115     /**
116      * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
117      * rendering into an Roo.Editor, defaults to false)
118      */
119     /**
120      * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
121      * {tag: "input", type: "text", size: "24", autocomplete: "off"})
122      */
123     /**
124      * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
125      */
126     /**
127      * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
128      * the dropdown list (defaults to undefined, with no header element)
129      */
130
131      /**
132      * @cfg {String/Roo.Template} tpl The template to use to render the output
133      */
134      
135      /**
136      * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
137      */
138     listWidth: undefined,
139     /**
140      * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
141      * mode = 'remote' or 'text' if mode = 'local')
142      */
143     displayField: undefined,
144     
145     /**
146      * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
147      * mode = 'remote' or 'value' if mode = 'local'). 
148      * Note: use of a valueField requires the user make a selection
149      * in order for a value to be mapped.
150      */
151     valueField: undefined,
152     
153     
154     /**
155      * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
156      * field's data value (defaults to the underlying DOM element's name)
157      */
158     hiddenName: undefined,
159     /**
160      * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
161      */
162     listClass: '',
163     /**
164      * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
165      */
166     selectedClass: 'active',
167     
168     /**
169      * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
170      */
171     shadow:'sides',
172     /**
173      * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
174      * anchor positions (defaults to 'tl-bl')
175      */
176     listAlign: 'tl-bl?',
177     /**
178      * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
179      */
180     maxHeight: 300,
181     /**
182      * @cfg {String} triggerAction The action to execute when the trigger field is activated.  Use 'all' to run the
183      * query specified by the allQuery config option (defaults to 'query')
184      */
185     triggerAction: 'query',
186     /**
187      * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
188      * (defaults to 4, does not apply if editable = false)
189      */
190     minChars : 4,
191     /**
192      * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
193      * delay (typeAheadDelay) if it matches a known value (defaults to false)
194      */
195     typeAhead: false,
196     /**
197      * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
198      * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
199      */
200     queryDelay: 500,
201     /**
202      * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
203      * filter queries will execute with page start and limit parameters.  Only applies when mode = 'remote' (defaults to 0)
204      */
205     pageSize: 0,
206     /**
207      * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus.  Only applies
208      * when editable = true (defaults to false)
209      */
210     selectOnFocus:false,
211     /**
212      * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
213      */
214     queryParam: 'query',
215     /**
216      * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies
217      * when mode = 'remote' (defaults to 'Loading...')
218      */
219     loadingText: 'Loading...',
220     /**
221      * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
222      */
223     resizable: false,
224     /**
225      * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
226      */
227     handleHeight : 8,
228     /**
229      * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
230      * traditional select (defaults to true)
231      */
232     editable: true,
233     /**
234      * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
235      */
236     allQuery: '',
237     /**
238      * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
239      */
240     mode: 'remote',
241     /**
242      * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
243      * listWidth has a higher value)
244      */
245     minListWidth : 70,
246     /**
247      * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
248      * allow the user to set arbitrary text into the field (defaults to false)
249      */
250     forceSelection:false,
251     /**
252      * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
253      * if typeAhead = true (defaults to 250)
254      */
255     typeAheadDelay : 250,
256     /**
257      * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
258      * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
259      */
260     valueNotFoundText : undefined,
261     /**
262      * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
263      */
264     blockFocus : false,
265     
266     /**
267      * @cfg {Boolean} disableClear Disable showing of clear button.
268      */
269     disableClear : false,
270     /**
271      * @cfg {Boolean} alwaysQuery  Disable caching of results, and always send query
272      */
273     alwaysQuery : false,
274     
275     /**
276      * @cfg {Boolean} multiple  (true|false) ComboBobArray, default false
277      */
278     multiple : false,
279     
280     /**
281      * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
282      */
283     invalidClass : "has-warning",
284     
285     /**
286      * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
287      */
288     validClass : "has-success",
289     
290     /**
291      * @cfg {Boolean} specialFilter (true|false) special filter default false
292      */
293     specialFilter : false,
294     
295     /**
296      * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
297      */
298     mobileTouchView : true,
299     
300     //private
301     addicon : false,
302     editicon: false,
303     
304     page: 0,
305     hasQuery: false,
306     append: false,
307     loadNext: false,
308     autoFocus : true,
309     tickable : false,
310     btnPosition : 'right',
311     triggerList : true,
312     showToggleBtn : true,
313     animate : true,
314     emptyResultText: 'Empty',
315     triggerText : 'Select',
316     
317     // element that contains real text value.. (when hidden is used..)
318     
319     getAutoCreate : function()
320     {
321         var cfg = false;
322         
323         /*
324          * Touch Devices
325          */
326         
327         if(Roo.isTouch && this.mobileTouchView){
328             cfg = this.getAutoCreateTouchView();
329             return cfg;;
330         }
331         
332         /*
333          *  Normal ComboBox
334          */
335         if(!this.tickable){
336             cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
337             return cfg;
338         }
339         
340         /*
341          *  ComboBox with tickable selections
342          */
343              
344         var align = this.labelAlign || this.parentLabelAlign();
345         
346         cfg = {
347             cls : 'form-group roo-combobox-tickable' //input-group
348         };
349         
350         var buttons = {
351             tag : 'div',
352             cls : 'tickable-buttons',
353             cn : [
354                 {
355                     tag : 'button',
356                     type : 'button',
357                     cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
358                     html : this.triggerText
359                 },
360                 {
361                     tag : 'button',
362                     type : 'button',
363                     name : 'ok',
364                     cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
365                     html : 'Done'
366                 },
367                 {
368                     tag : 'button',
369                     type : 'button',
370                     name : 'cancel',
371                     cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
372                     html : 'Cancel'
373                 }
374             ]
375         };
376         
377         if(this.editable){
378             buttons.cn.unshift({
379                 tag: 'input',
380                 cls: 'select2-search-field-input'
381             });
382         }
383         
384         var _this = this;
385         
386         Roo.each(buttons.cn, function(c){
387             if (_this.size) {
388                 c.cls += ' btn-' + _this.size;
389             }
390
391             if (_this.disabled) {
392                 c.disabled = true;
393             }
394         });
395         
396         var box = {
397             tag: 'div',
398             cn: [
399                 {
400                     tag: 'input',
401                     type : 'hidden',
402                     cls: 'form-hidden-field'
403                 },
404                 {
405                     tag: 'ul',
406                     cls: 'select2-choices',
407                     cn:[
408                         {
409                             tag: 'li',
410                             cls: 'select2-search-field',
411                             cn: [
412
413                                 buttons
414                             ]
415                         }
416                     ]
417                 }
418             ]
419         };
420         
421         var combobox = {
422             cls: 'select2-container input-group select2-container-multi',
423             cn: [
424                 box
425 //                {
426 //                    tag: 'ul',
427 //                    cls: 'typeahead typeahead-long dropdown-menu',
428 //                    style: 'display:none; max-height:' + this.maxHeight + 'px;'
429 //                }
430             ]
431         };
432         
433         if(this.hasFeedback && !this.allowBlank){
434             
435             var feedback = {
436                 tag: 'span',
437                 cls: 'glyphicon form-control-feedback'
438             };
439
440             combobox.cn.push(feedback);
441         }
442         
443         if (align ==='left' && this.fieldLabel.length) {
444             
445                 Roo.log("left and has label");
446                 cfg.cn = [
447                     
448                     {
449                         tag: 'label',
450                         'for' :  id,
451                         cls : 'control-label col-sm-' + this.labelWidth,
452                         html : this.fieldLabel
453                         
454                     },
455                     {
456                         cls : "col-sm-" + (12 - this.labelWidth), 
457                         cn: [
458                             combobox
459                         ]
460                     }
461                     
462                 ];
463         } else if ( this.fieldLabel.length) {
464                 Roo.log(" label");
465                  cfg.cn = [
466                    
467                     {
468                         tag: 'label',
469                         //cls : 'input-group-addon',
470                         html : this.fieldLabel
471                         
472                     },
473                     
474                     combobox
475                     
476                 ];
477
478         } else {
479             
480                 Roo.log(" no label && no align");
481                 cfg = combobox
482                      
483                 
484         }
485          
486         var settings=this;
487         ['xs','sm','md','lg'].map(function(size){
488             if (settings[size]) {
489                 cfg.cls += ' col-' + size + '-' + settings[size];
490             }
491         });
492         
493         return cfg;
494         
495     },
496     
497     _initEventsCalled : false,
498     
499     // private
500     initEvents: function()
501     {
502         
503         if (this._initEventsCalled) { // as we call render... prevent looping...
504             return;
505         }
506         this._initEventsCalled = true;
507         
508         if (!this.store) {
509             throw "can not find store for combo";
510         }
511         
512         this.store = Roo.factory(this.store, Roo.data);
513         
514         // if we are building from html. then this element is so complex, that we can not really
515         // use the rendered HTML.
516         // so we have to trash and replace the previous code.
517         if (Roo.XComponent.build_from_html) {
518             
519             // remove this element....
520             var e = this.el.dom, k=0;
521             while (e ) { e = e.previousSibling;  ++k;}
522
523             this.el.remove();
524             
525             this.el=false;
526             this.rendered = false;
527             
528             this.render(this.parent().getChildContainer(true), k);
529             
530             
531             
532         }
533         
534         
535         /*
536          * Touch Devices
537          */
538         
539         if(Roo.isTouch && this.mobileTouchView){
540             this.initTouchView();
541             return;
542         }
543         
544         if(this.tickable){
545             this.initTickableEvents();
546             return;
547         }
548         
549         Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
550         
551         if(this.hiddenName){
552             
553             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
554             
555             this.hiddenField.dom.value =
556                 this.hiddenValue !== undefined ? this.hiddenValue :
557                 this.value !== undefined ? this.value : '';
558
559             // prevent input submission
560             this.el.dom.removeAttribute('name');
561             this.hiddenField.dom.setAttribute('name', this.hiddenName);
562              
563              
564         }
565         //if(Roo.isGecko){
566         //    this.el.dom.setAttribute('autocomplete', 'off');
567         //}
568         
569         var cls = 'x-combo-list';
570         
571         //this.list = new Roo.Layer({
572         //    shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
573         //});
574         
575         var _this = this;
576         
577         (function(){
578             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
579             _this.list.setWidth(lw);
580         }).defer(100);
581         
582         this.list.on('mouseover', this.onViewOver, this);
583         this.list.on('mousemove', this.onViewMove, this);
584         
585         this.list.on('scroll', this.onViewScroll, this);
586         
587         /*
588         this.list.swallowEvent('mousewheel');
589         this.assetHeight = 0;
590
591         if(this.title){
592             this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
593             this.assetHeight += this.header.getHeight();
594         }
595
596         this.innerList = this.list.createChild({cls:cls+'-inner'});
597         this.innerList.on('mouseover', this.onViewOver, this);
598         this.innerList.on('mousemove', this.onViewMove, this);
599         this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
600         
601         if(this.allowBlank && !this.pageSize && !this.disableClear){
602             this.footer = this.list.createChild({cls:cls+'-ft'});
603             this.pageTb = new Roo.Toolbar(this.footer);
604            
605         }
606         if(this.pageSize){
607             this.footer = this.list.createChild({cls:cls+'-ft'});
608             this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
609                     {pageSize: this.pageSize});
610             
611         }
612         
613         if (this.pageTb && this.allowBlank && !this.disableClear) {
614             var _this = this;
615             this.pageTb.add(new Roo.Toolbar.Fill(), {
616                 cls: 'x-btn-icon x-btn-clear',
617                 text: ' ',
618                 handler: function()
619                 {
620                     _this.collapse();
621                     _this.clearValue();
622                     _this.onSelect(false, -1);
623                 }
624             });
625         }
626         if (this.footer) {
627             this.assetHeight += this.footer.getHeight();
628         }
629         */
630             
631         if(!this.tpl){
632             this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
633         }
634
635         this.view = new Roo.View(this.list, this.tpl, {
636             singleSelect:true, store: this.store, selectedClass: this.selectedClass
637         });
638         //this.view.wrapEl.setDisplayed(false);
639         this.view.on('click', this.onViewClick, this);
640         
641         
642         
643         this.store.on('beforeload', this.onBeforeLoad, this);
644         this.store.on('load', this.onLoad, this);
645         this.store.on('loadexception', this.onLoadException, this);
646         /*
647         if(this.resizable){
648             this.resizer = new Roo.Resizable(this.list,  {
649                pinned:true, handles:'se'
650             });
651             this.resizer.on('resize', function(r, w, h){
652                 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
653                 this.listWidth = w;
654                 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
655                 this.restrictHeight();
656             }, this);
657             this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
658         }
659         */
660         if(!this.editable){
661             this.editable = true;
662             this.setEditable(false);
663         }
664         
665         /*
666         
667         if (typeof(this.events.add.listeners) != 'undefined') {
668             
669             this.addicon = this.wrap.createChild(
670                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });  
671        
672             this.addicon.on('click', function(e) {
673                 this.fireEvent('add', this);
674             }, this);
675         }
676         if (typeof(this.events.edit.listeners) != 'undefined') {
677             
678             this.editicon = this.wrap.createChild(
679                 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });  
680             if (this.addicon) {
681                 this.editicon.setStyle('margin-left', '40px');
682             }
683             this.editicon.on('click', function(e) {
684                 
685                 // we fire even  if inothing is selected..
686                 this.fireEvent('edit', this, this.lastData );
687                 
688             }, this);
689         }
690         */
691         
692         this.keyNav = new Roo.KeyNav(this.inputEl(), {
693             "up" : function(e){
694                 this.inKeyMode = true;
695                 this.selectPrev();
696             },
697
698             "down" : function(e){
699                 if(!this.isExpanded()){
700                     this.onTriggerClick();
701                 }else{
702                     this.inKeyMode = true;
703                     this.selectNext();
704                 }
705             },
706
707             "enter" : function(e){
708 //                this.onViewClick();
709                 //return true;
710                 this.collapse();
711                 
712                 if(this.fireEvent("specialkey", this, e)){
713                     this.onViewClick(false);
714                 }
715                 
716                 return true;
717             },
718
719             "esc" : function(e){
720                 this.collapse();
721             },
722
723             "tab" : function(e){
724                 this.collapse();
725                 
726                 if(this.fireEvent("specialkey", this, e)){
727                     this.onViewClick(false);
728                 }
729                 
730                 return true;
731             },
732
733             scope : this,
734
735             doRelay : function(foo, bar, hname){
736                 if(hname == 'down' || this.scope.isExpanded()){
737                    return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
738                 }
739                 return true;
740             },
741
742             forceKeyDown: true
743         });
744         
745         
746         this.queryDelay = Math.max(this.queryDelay || 10,
747                 this.mode == 'local' ? 10 : 250);
748         
749         
750         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
751         
752         if(this.typeAhead){
753             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
754         }
755         if(this.editable !== false){
756             this.inputEl().on("keyup", this.onKeyUp, this);
757         }
758         if(this.forceSelection){
759             this.inputEl().on('blur', this.doForce, this);
760         }
761         
762         if(this.multiple){
763             this.choices = this.el.select('ul.select2-choices', true).first();
764             this.searchField = this.el.select('ul li.select2-search-field', true).first();
765         }
766     },
767     
768     initTickableEvents: function()
769     {   
770         this.createList();
771         
772         if(this.hiddenName){
773             
774             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
775             
776             this.hiddenField.dom.value =
777                 this.hiddenValue !== undefined ? this.hiddenValue :
778                 this.value !== undefined ? this.value : '';
779
780             // prevent input submission
781             this.el.dom.removeAttribute('name');
782             this.hiddenField.dom.setAttribute('name', this.hiddenName);
783              
784              
785         }
786         
787 //        this.list = this.el.select('ul.dropdown-menu',true).first();
788         
789         this.choices = this.el.select('ul.select2-choices', true).first();
790         this.searchField = this.el.select('ul li.select2-search-field', true).first();
791         if(this.triggerList){
792             this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
793         }
794          
795         this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
796         this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
797         
798         this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
799         this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
800         
801         this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
802         this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
803         
804         this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
805         this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
806         this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
807         
808         this.okBtn.hide();
809         this.cancelBtn.hide();
810         
811         var _this = this;
812         
813         (function(){
814             var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
815             _this.list.setWidth(lw);
816         }).defer(100);
817         
818         this.list.on('mouseover', this.onViewOver, this);
819         this.list.on('mousemove', this.onViewMove, this);
820         
821         this.list.on('scroll', this.onViewScroll, this);
822         
823         if(!this.tpl){
824             this.tpl = '<li class="select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></li>';
825         }
826
827         this.view = new Roo.View(this.list, this.tpl, {
828             singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
829         });
830         
831         //this.view.wrapEl.setDisplayed(false);
832         this.view.on('click', this.onViewClick, this);
833         
834         
835         
836         this.store.on('beforeload', this.onBeforeLoad, this);
837         this.store.on('load', this.onLoad, this);
838         this.store.on('loadexception', this.onLoadException, this);
839         
840         if(this.editable){
841             this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
842                 "up" : function(e){
843                     this.inKeyMode = true;
844                     this.selectPrev();
845                 },
846
847                 "down" : function(e){
848                     this.inKeyMode = true;
849                     this.selectNext();
850                 },
851
852                 "enter" : function(e){
853                     if(this.fireEvent("specialkey", this, e)){
854                         this.onViewClick(false);
855                     }
856                     
857                     return true;
858                 },
859
860                 "esc" : function(e){
861                     this.onTickableFooterButtonClick(e, false, false);
862                 },
863
864                 "tab" : function(e){
865                     this.fireEvent("specialkey", this, e);
866                     
867                     this.onTickableFooterButtonClick(e, false, false);
868                     
869                     return true;
870                 },
871
872                 scope : this,
873
874                 doRelay : function(e, fn, key){
875                     if(this.scope.isExpanded()){
876                        return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
877                     }
878                     return true;
879                 },
880
881                 forceKeyDown: true
882             });
883         }
884         
885         this.queryDelay = Math.max(this.queryDelay || 10,
886                 this.mode == 'local' ? 10 : 250);
887         
888         
889         this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
890         
891         if(this.typeAhead){
892             this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
893         }
894         
895         if(this.editable !== false){
896             this.tickableInputEl().on("keyup", this.onKeyUp, this);
897         }
898         
899     },
900
901     onDestroy : function(){
902         if(this.view){
903             this.view.setStore(null);
904             this.view.el.removeAllListeners();
905             this.view.el.remove();
906             this.view.purgeListeners();
907         }
908         if(this.list){
909             this.list.dom.innerHTML  = '';
910         }
911         
912         if(this.store){
913             this.store.un('beforeload', this.onBeforeLoad, this);
914             this.store.un('load', this.onLoad, this);
915             this.store.un('loadexception', this.onLoadException, this);
916         }
917         Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
918     },
919
920     // private
921     fireKey : function(e){
922         if(e.isNavKeyPress() && !this.list.isVisible()){
923             this.fireEvent("specialkey", this, e);
924         }
925     },
926
927     // private
928     onResize: function(w, h){
929 //        Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
930 //        
931 //        if(typeof w != 'number'){
932 //            // we do not handle it!?!?
933 //            return;
934 //        }
935 //        var tw = this.trigger.getWidth();
936 //       // tw += this.addicon ? this.addicon.getWidth() : 0;
937 //       // tw += this.editicon ? this.editicon.getWidth() : 0;
938 //        var x = w - tw;
939 //        this.inputEl().setWidth( this.adjustWidth('input', x));
940 //            
941 //        //this.trigger.setStyle('left', x+'px');
942 //        
943 //        if(this.list && this.listWidth === undefined){
944 //            var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
945 //            this.list.setWidth(lw);
946 //            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
947 //        }
948         
949     
950         
951     },
952
953     /**
954      * Allow or prevent the user from directly editing the field text.  If false is passed,
955      * the user will only be able to select from the items defined in the dropdown list.  This method
956      * is the runtime equivalent of setting the 'editable' config option at config time.
957      * @param {Boolean} value True to allow the user to directly edit the field text
958      */
959     setEditable : function(value){
960         if(value == this.editable){
961             return;
962         }
963         this.editable = value;
964         if(!value){
965             this.inputEl().dom.setAttribute('readOnly', true);
966             this.inputEl().on('mousedown', this.onTriggerClick,  this);
967             this.inputEl().addClass('x-combo-noedit');
968         }else{
969             this.inputEl().dom.setAttribute('readOnly', false);
970             this.inputEl().un('mousedown', this.onTriggerClick,  this);
971             this.inputEl().removeClass('x-combo-noedit');
972         }
973     },
974
975     // private
976     
977     onBeforeLoad : function(combo,opts){
978         if(!this.hasFocus){
979             return;
980         }
981          if (!opts.add) {
982             this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
983          }
984         this.restrictHeight();
985         this.selectedIndex = -1;
986     },
987
988     // private
989     onLoad : function(){
990         
991         this.hasQuery = false;
992         
993         if(!this.hasFocus){
994             return;
995         }
996         
997         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
998             this.loading.hide();
999         }
1000              
1001         if(this.store.getCount() > 0){
1002             this.expand();
1003             this.restrictHeight();
1004             if(this.lastQuery == this.allQuery){
1005                 if(this.editable && !this.tickable){
1006                     this.inputEl().dom.select();
1007                 }
1008                 
1009                 if(
1010                     !this.selectByValue(this.value, true) &&
1011                     this.autoFocus && 
1012                     (
1013                         !this.store.lastOptions ||
1014                         typeof(this.store.lastOptions.add) == 'undefined' || 
1015                         this.store.lastOptions.add != true
1016                     )
1017                 ){
1018                     this.select(0, true);
1019                 }
1020             }else{
1021                 if(this.autoFocus){
1022                     this.selectNext();
1023                 }
1024                 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1025                     this.taTask.delay(this.typeAheadDelay);
1026                 }
1027             }
1028         }else{
1029             this.onEmptyResults();
1030         }
1031         
1032         //this.el.focus();
1033     },
1034     // private
1035     onLoadException : function()
1036     {
1037         this.hasQuery = false;
1038         
1039         if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1040             this.loading.hide();
1041         }
1042         
1043         if(this.tickable && this.editable){
1044             return;
1045         }
1046         
1047         this.collapse();
1048         // only causes errors at present
1049         //Roo.log(this.store.reader.jsonData);
1050         //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1051             // fixme
1052             //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1053         //}
1054         
1055         
1056     },
1057     // private
1058     onTypeAhead : function(){
1059         if(this.store.getCount() > 0){
1060             var r = this.store.getAt(0);
1061             var newValue = r.data[this.displayField];
1062             var len = newValue.length;
1063             var selStart = this.getRawValue().length;
1064             
1065             if(selStart != len){
1066                 this.setRawValue(newValue);
1067                 this.selectText(selStart, newValue.length);
1068             }
1069         }
1070     },
1071
1072     // private
1073     onSelect : function(record, index){
1074         
1075         if(this.fireEvent('beforeselect', this, record, index) !== false){
1076         
1077             this.setFromData(index > -1 ? record.data : false);
1078             
1079             this.collapse();
1080             this.fireEvent('select', this, record, index);
1081         }
1082     },
1083
1084     /**
1085      * Returns the currently selected field value or empty string if no value is set.
1086      * @return {String} value The selected value
1087      */
1088     getValue : function(){
1089         
1090         if(this.multiple){
1091             return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1092         }
1093         
1094         if(this.valueField){
1095             return typeof this.value != 'undefined' ? this.value : '';
1096         }else{
1097             return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1098         }
1099     },
1100
1101     /**
1102      * Clears any text/value currently set in the field
1103      */
1104     clearValue : function(){
1105         if(this.hiddenField){
1106             this.hiddenField.dom.value = '';
1107         }
1108         this.value = '';
1109         this.setRawValue('');
1110         this.lastSelectionText = '';
1111         this.lastData = false;
1112         
1113         var close = this.closeTriggerEl();
1114         
1115         if(close){
1116             close.hide();
1117         }
1118         
1119     },
1120
1121     /**
1122      * Sets the specified value into the field.  If the value finds a match, the corresponding record text
1123      * will be displayed in the field.  If the value does not match the data value of an existing item,
1124      * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1125      * Otherwise the field will be blank (although the value will still be set).
1126      * @param {String} value The value to match
1127      */
1128     setValue : function(v){
1129         if(this.multiple){
1130             this.syncValue();
1131             return;
1132         }
1133         
1134         var text = v;
1135         if(this.valueField){
1136             var r = this.findRecord(this.valueField, v);
1137             if(r){
1138                 text = r.data[this.displayField];
1139             }else if(this.valueNotFoundText !== undefined){
1140                 text = this.valueNotFoundText;
1141             }
1142         }
1143         this.lastSelectionText = text;
1144         if(this.hiddenField){
1145             this.hiddenField.dom.value = v;
1146         }
1147         Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1148         this.value = v;
1149         
1150         var close = this.closeTriggerEl();
1151         
1152         if(close){
1153             (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1154         }
1155     },
1156     /**
1157      * @property {Object} the last set data for the element
1158      */
1159     
1160     lastData : false,
1161     /**
1162      * Sets the value of the field based on a object which is related to the record format for the store.
1163      * @param {Object} value the value to set as. or false on reset?
1164      */
1165     setFromData : function(o){
1166         
1167         if(this.multiple){
1168             this.addItem(o);
1169             return;
1170         }
1171             
1172         var dv = ''; // display value
1173         var vv = ''; // value value..
1174         this.lastData = o;
1175         if (this.displayField) {
1176             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1177         } else {
1178             // this is an error condition!!!
1179             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
1180         }
1181         
1182         if(this.valueField){
1183             vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1184         }
1185         
1186         var close = this.closeTriggerEl();
1187         
1188         if(close){
1189             (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1190         }
1191         
1192         if(this.hiddenField){
1193             this.hiddenField.dom.value = vv;
1194             
1195             this.lastSelectionText = dv;
1196             Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1197             this.value = vv;
1198             return;
1199         }
1200         // no hidden field.. - we store the value in 'value', but still display
1201         // display field!!!!
1202         this.lastSelectionText = dv;
1203         Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1204         this.value = vv;
1205         
1206         
1207         
1208     },
1209     // private
1210     reset : function(){
1211         // overridden so that last data is reset..
1212         
1213         if(this.multiple){
1214             this.clearItem();
1215             return;
1216         }
1217         
1218         this.setValue(this.originalValue);
1219         this.clearInvalid();
1220         this.lastData = false;
1221         if (this.view) {
1222             this.view.clearSelections();
1223         }
1224     },
1225     // private
1226     findRecord : function(prop, value){
1227         var record;
1228         if(this.store.getCount() > 0){
1229             this.store.each(function(r){
1230                 if(r.data[prop] == value){
1231                     record = r;
1232                     return false;
1233                 }
1234                 return true;
1235             });
1236         }
1237         return record;
1238     },
1239     
1240     getName: function()
1241     {
1242         // returns hidden if it's set..
1243         if (!this.rendered) {return ''};
1244         return !this.hiddenName && this.inputEl().dom.name  ? this.inputEl().dom.name : (this.hiddenName || '');
1245         
1246     },
1247     // private
1248     onViewMove : function(e, t){
1249         this.inKeyMode = false;
1250     },
1251
1252     // private
1253     onViewOver : function(e, t){
1254         if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1255             return;
1256         }
1257         var item = this.view.findItemFromChild(t);
1258         
1259         if(item){
1260             var index = this.view.indexOf(item);
1261             this.select(index, false);
1262         }
1263     },
1264
1265     // private
1266     onViewClick : function(view, doFocus, el, e)
1267     {
1268         var index = this.view.getSelectedIndexes()[0];
1269         
1270         var r = this.store.getAt(index);
1271         
1272         if(this.tickable){
1273             
1274             if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1275                 return;
1276             }
1277             
1278             var rm = false;
1279             var _this = this;
1280             
1281             Roo.each(this.tickItems, function(v,k){
1282                 
1283                 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1284                     Roo.log(v);
1285                     _this.tickItems.splice(k, 1);
1286                     
1287                     if(typeof(e) == 'undefined' && view == false){
1288                         Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1289                     }
1290                     
1291                     rm = true;
1292                     return;
1293                 }
1294             });
1295             
1296             if(rm){
1297                 return;
1298             }
1299             
1300             if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1301                 this.tickItems.push(r.data);
1302             }
1303             
1304             if(typeof(e) == 'undefined' && view == false){
1305                 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1306             }
1307                     
1308             return;
1309         }
1310         
1311         if(r){
1312             this.onSelect(r, index);
1313         }
1314         if(doFocus !== false && !this.blockFocus){
1315             this.inputEl().focus();
1316         }
1317     },
1318
1319     // private
1320     restrictHeight : function(){
1321         //this.innerList.dom.style.height = '';
1322         //var inner = this.innerList.dom;
1323         //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1324         //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1325         //this.list.beginUpdate();
1326         //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1327         this.list.alignTo(this.inputEl(), this.listAlign);
1328         this.list.alignTo(this.inputEl(), this.listAlign);
1329         //this.list.endUpdate();
1330     },
1331
1332     // private
1333     onEmptyResults : function(){
1334         
1335         if(this.tickable && this.editable){
1336             this.restrictHeight();
1337             return;
1338         }
1339         
1340         this.collapse();
1341     },
1342
1343     /**
1344      * Returns true if the dropdown list is expanded, else false.
1345      */
1346     isExpanded : function(){
1347         return this.list.isVisible();
1348     },
1349
1350     /**
1351      * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1352      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1353      * @param {String} value The data value of the item to select
1354      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1355      * selected item if it is not currently in view (defaults to true)
1356      * @return {Boolean} True if the value matched an item in the list, else false
1357      */
1358     selectByValue : function(v, scrollIntoView){
1359         if(v !== undefined && v !== null){
1360             var r = this.findRecord(this.valueField || this.displayField, v);
1361             if(r){
1362                 this.select(this.store.indexOf(r), scrollIntoView);
1363                 return true;
1364             }
1365         }
1366         return false;
1367     },
1368
1369     /**
1370      * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1371      * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1372      * @param {Number} index The zero-based index of the list item to select
1373      * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1374      * selected item if it is not currently in view (defaults to true)
1375      */
1376     select : function(index, scrollIntoView){
1377         this.selectedIndex = index;
1378         this.view.select(index);
1379         if(scrollIntoView !== false){
1380             var el = this.view.getNode(index);
1381             /*
1382              * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1383              */
1384             if(el){
1385                 this.list.scrollChildIntoView(el, false);
1386             }
1387         }
1388     },
1389
1390     // private
1391     selectNext : function(){
1392         var ct = this.store.getCount();
1393         if(ct > 0){
1394             if(this.selectedIndex == -1){
1395                 this.select(0);
1396             }else if(this.selectedIndex < ct-1){
1397                 this.select(this.selectedIndex+1);
1398             }
1399         }
1400     },
1401
1402     // private
1403     selectPrev : function(){
1404         var ct = this.store.getCount();
1405         if(ct > 0){
1406             if(this.selectedIndex == -1){
1407                 this.select(0);
1408             }else if(this.selectedIndex != 0){
1409                 this.select(this.selectedIndex-1);
1410             }
1411         }
1412     },
1413
1414     // private
1415     onKeyUp : function(e){
1416         if(this.editable !== false && !e.isSpecialKey()){
1417             this.lastKey = e.getKey();
1418             this.dqTask.delay(this.queryDelay);
1419         }
1420     },
1421
1422     // private
1423     validateBlur : function(){
1424         return !this.list || !this.list.isVisible();   
1425     },
1426
1427     // private
1428     initQuery : function(){
1429         
1430         var v = this.getRawValue();
1431         
1432         if(this.tickable && this.editable){
1433             v = this.tickableInputEl().getValue();
1434         }
1435         
1436         this.doQuery(v);
1437     },
1438
1439     // private
1440     doForce : function(){
1441         if(this.inputEl().dom.value.length > 0){
1442             this.inputEl().dom.value =
1443                 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1444              
1445         }
1446     },
1447
1448     /**
1449      * Execute a query to filter the dropdown list.  Fires the beforequery event prior to performing the
1450      * query allowing the query action to be canceled if needed.
1451      * @param {String} query The SQL query to execute
1452      * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1453      * in the field than the minimum specified by the minChars config option.  It also clears any filter previously
1454      * saved in the current store (defaults to false)
1455      */
1456     doQuery : function(q, forceAll){
1457         
1458         if(q === undefined || q === null){
1459             q = '';
1460         }
1461         var qe = {
1462             query: q,
1463             forceAll: forceAll,
1464             combo: this,
1465             cancel:false
1466         };
1467         if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1468             return false;
1469         }
1470         q = qe.query;
1471         
1472         forceAll = qe.forceAll;
1473         if(forceAll === true || (q.length >= this.minChars)){
1474             
1475             this.hasQuery = true;
1476             
1477             if(this.lastQuery != q || this.alwaysQuery){
1478                 this.lastQuery = q;
1479                 if(this.mode == 'local'){
1480                     this.selectedIndex = -1;
1481                     if(forceAll){
1482                         this.store.clearFilter();
1483                     }else{
1484                         
1485                         if(this.specialFilter){
1486                             this.fireEvent('specialfilter', this);
1487                             this.onLoad();
1488                             return;
1489                         }
1490                         
1491                         this.store.filter(this.displayField, q);
1492                     }
1493                     
1494                     this.store.fireEvent("datachanged", this.store);
1495                     
1496                     this.onLoad();
1497                     
1498                     
1499                 }else{
1500                     
1501                     this.store.baseParams[this.queryParam] = q;
1502                     
1503                     var options = {params : this.getParams(q)};
1504                     
1505                     if(this.loadNext){
1506                         options.add = true;
1507                         options.params.start = this.page * this.pageSize;
1508                     }
1509                     
1510                     this.store.load(options);
1511                     
1512                     /*
1513                      *  this code will make the page width larger, at the beginning, the list not align correctly, 
1514                      *  we should expand the list on onLoad
1515                      *  so command out it
1516                      */
1517 //                    this.expand();
1518                 }
1519             }else{
1520                 this.selectedIndex = -1;
1521                 this.onLoad();   
1522             }
1523         }
1524         
1525         this.loadNext = false;
1526     },
1527     
1528     // private
1529     getParams : function(q){
1530         var p = {};
1531         //p[this.queryParam] = q;
1532         
1533         if(this.pageSize){
1534             p.start = 0;
1535             p.limit = this.pageSize;
1536         }
1537         return p;
1538     },
1539
1540     /**
1541      * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1542      */
1543     collapse : function(){
1544         if(!this.isExpanded()){
1545             return;
1546         }
1547         
1548         this.list.hide();
1549         
1550         if(this.tickable){
1551             this.hasFocus = false;
1552             this.okBtn.hide();
1553             this.cancelBtn.hide();
1554             this.trigger.show();
1555             
1556             if(this.editable){
1557                 this.tickableInputEl().dom.value = '';
1558                 this.tickableInputEl().blur();
1559             }
1560             
1561         }
1562         
1563         Roo.get(document).un('mousedown', this.collapseIf, this);
1564         Roo.get(document).un('mousewheel', this.collapseIf, this);
1565         if (!this.editable) {
1566             Roo.get(document).un('keydown', this.listKeyPress, this);
1567         }
1568         this.fireEvent('collapse', this);
1569     },
1570
1571     // private
1572     collapseIf : function(e){
1573         var in_combo  = e.within(this.el);
1574         var in_list =  e.within(this.list);
1575         var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1576         
1577         if (in_combo || in_list || is_list) {
1578             //e.stopPropagation();
1579             return;
1580         }
1581         
1582         if(this.tickable){
1583             this.onTickableFooterButtonClick(e, false, false);
1584         }
1585
1586         this.collapse();
1587         
1588     },
1589
1590     /**
1591      * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1592      */
1593     expand : function(){
1594        
1595         if(this.isExpanded() || !this.hasFocus){
1596             return;
1597         }
1598         
1599         var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1600         this.list.setWidth(lw);
1601         
1602         
1603          Roo.log('expand');
1604         
1605         this.list.show();
1606         
1607         this.restrictHeight();
1608         
1609         if(this.tickable){
1610             
1611             this.tickItems = Roo.apply([], this.item);
1612             
1613             this.okBtn.show();
1614             this.cancelBtn.show();
1615             this.trigger.hide();
1616             
1617             if(this.editable){
1618                 this.tickableInputEl().focus();
1619             }
1620             
1621         }
1622         
1623         Roo.get(document).on('mousedown', this.collapseIf, this);
1624         Roo.get(document).on('mousewheel', this.collapseIf, this);
1625         if (!this.editable) {
1626             Roo.get(document).on('keydown', this.listKeyPress, this);
1627         }
1628         
1629         this.fireEvent('expand', this);
1630     },
1631
1632     // private
1633     // Implements the default empty TriggerField.onTriggerClick function
1634     onTriggerClick : function(e)
1635     {
1636         Roo.log('trigger click');
1637         
1638         if(this.disabled || !this.triggerList){
1639             return;
1640         }
1641         
1642         this.page = 0;
1643         this.loadNext = false;
1644         
1645         if(this.isExpanded()){
1646             this.collapse();
1647             if (!this.blockFocus) {
1648                 this.inputEl().focus();
1649             }
1650             
1651         }else {
1652             this.hasFocus = true;
1653             if(this.triggerAction == 'all') {
1654                 this.doQuery(this.allQuery, true);
1655             } else {
1656                 this.doQuery(this.getRawValue());
1657             }
1658             if (!this.blockFocus) {
1659                 this.inputEl().focus();
1660             }
1661         }
1662     },
1663     
1664     onTickableTriggerClick : function(e)
1665     {
1666         if(this.disabled){
1667             return;
1668         }
1669         
1670         this.page = 0;
1671         this.loadNext = false;
1672         this.hasFocus = true;
1673         
1674         if(this.triggerAction == 'all') {
1675             this.doQuery(this.allQuery, true);
1676         } else {
1677             this.doQuery(this.getRawValue());
1678         }
1679     },
1680     
1681     onSearchFieldClick : function(e)
1682     {
1683         if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1684             this.onTickableFooterButtonClick(e, false, false);
1685             return;
1686         }
1687         
1688         if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1689             return;
1690         }
1691         
1692         this.page = 0;
1693         this.loadNext = false;
1694         this.hasFocus = true;
1695         
1696         if(this.triggerAction == 'all') {
1697             this.doQuery(this.allQuery, true);
1698         } else {
1699             this.doQuery(this.getRawValue());
1700         }
1701     },
1702     
1703     listKeyPress : function(e)
1704     {
1705         //Roo.log('listkeypress');
1706         // scroll to first matching element based on key pres..
1707         if (e.isSpecialKey()) {
1708             return false;
1709         }
1710         var k = String.fromCharCode(e.getKey()).toUpperCase();
1711         //Roo.log(k);
1712         var match  = false;
1713         var csel = this.view.getSelectedNodes();
1714         var cselitem = false;
1715         if (csel.length) {
1716             var ix = this.view.indexOf(csel[0]);
1717             cselitem  = this.store.getAt(ix);
1718             if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1719                 cselitem = false;
1720             }
1721             
1722         }
1723         
1724         this.store.each(function(v) { 
1725             if (cselitem) {
1726                 // start at existing selection.
1727                 if (cselitem.id == v.id) {
1728                     cselitem = false;
1729                 }
1730                 return true;
1731             }
1732                 
1733             if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1734                 match = this.store.indexOf(v);
1735                 return false;
1736             }
1737             return true;
1738         }, this);
1739         
1740         if (match === false) {
1741             return true; // no more action?
1742         }
1743         // scroll to?
1744         this.view.select(match);
1745         var sn = Roo.get(this.view.getSelectedNodes()[0])
1746         sn.scrollIntoView(sn.dom.parentNode, false);
1747     },
1748     
1749     onViewScroll : function(e, t){
1750         
1751         if(this.view.el.getScroll().top == 0 ||this.view.el.getScroll().top < this.view.el.dom.scrollHeight - this.view.el.dom.clientHeight || !this.hasFocus || !this.append || this.hasQuery){
1752             return;
1753         }
1754         
1755         this.hasQuery = true;
1756         
1757         this.loading = this.list.select('.loading', true).first();
1758         
1759         if(this.loading === null){
1760             this.list.createChild({
1761                 tag: 'div',
1762                 cls: 'loading select2-more-results select2-active',
1763                 html: 'Loading more results...'
1764             })
1765             
1766             this.loading = this.list.select('.loading', true).first();
1767             
1768             this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1769             
1770             this.loading.hide();
1771         }
1772         
1773         this.loading.show();
1774         
1775         var _combo = this;
1776         
1777         this.page++;
1778         this.loadNext = true;
1779         
1780         (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1781         
1782         return;
1783     },
1784     
1785     addItem : function(o)
1786     {   
1787         var dv = ''; // display value
1788         
1789         if (this.displayField) {
1790             dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1791         } else {
1792             // this is an error condition!!!
1793             Roo.log('no  displayField value set for '+ (this.name ? this.name : this.id));
1794         }
1795         
1796         if(!dv.length){
1797             return;
1798         }
1799         
1800         var choice = this.choices.createChild({
1801             tag: 'li',
1802             cls: 'select2-search-choice',
1803             cn: [
1804                 {
1805                     tag: 'div',
1806                     html: dv
1807                 },
1808                 {
1809                     tag: 'a',
1810                     href: '#',
1811                     cls: 'select2-search-choice-close',
1812                     tabindex: '-1'
1813                 }
1814             ]
1815             
1816         }, this.searchField);
1817         
1818         var close = choice.select('a.select2-search-choice-close', true).first()
1819         
1820         close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1821         
1822         this.item.push(o);
1823         
1824         this.lastData = o;
1825         
1826         this.syncValue();
1827         
1828         this.inputEl().dom.value = '';
1829         
1830         this.validate();
1831     },
1832     
1833     onRemoveItem : function(e, _self, o)
1834     {
1835         e.preventDefault();
1836         
1837         this.lastItem = Roo.apply([], this.item);
1838         
1839         var index = this.item.indexOf(o.data) * 1;
1840         
1841         if( index < 0){
1842             Roo.log('not this item?!');
1843             return;
1844         }
1845         
1846         this.item.splice(index, 1);
1847         o.item.remove();
1848         
1849         this.syncValue();
1850         
1851         this.fireEvent('remove', this, e);
1852         
1853         this.validate();
1854         
1855     },
1856     
1857     syncValue : function()
1858     {
1859         if(!this.item.length){
1860             this.clearValue();
1861             return;
1862         }
1863             
1864         var value = [];
1865         var _this = this;
1866         Roo.each(this.item, function(i){
1867             if(_this.valueField){
1868                 value.push(i[_this.valueField]);
1869                 return;
1870             }
1871
1872             value.push(i);
1873         });
1874
1875         this.value = value.join(',');
1876
1877         if(this.hiddenField){
1878             this.hiddenField.dom.value = this.value;
1879         }
1880         
1881         this.store.fireEvent("datachanged", this.store);
1882     },
1883     
1884     clearItem : function()
1885     {
1886         if(!this.multiple){
1887             return;
1888         }
1889         
1890         this.item = [];
1891         
1892         Roo.each(this.choices.select('>li.select2-search-choice', true).elements, function(c){
1893            c.remove();
1894         });
1895         
1896         this.syncValue();
1897         
1898         this.validate();
1899         
1900         if(this.tickable && !Roo.isTouch){
1901             this.view.refresh();
1902         }
1903     },
1904     
1905     inputEl: function ()
1906     {
1907         if(Roo.isTouch && this.mobileTouchView){
1908             return this.el.select('input.form-control',true).first();
1909         }
1910         
1911         if(this.tickable){
1912             return this.searchField;
1913         }
1914         
1915         return this.el.select('input.form-control',true).first();
1916     },
1917     
1918     
1919     onTickableFooterButtonClick : function(e, btn, el)
1920     {
1921         e.preventDefault();
1922         
1923         this.lastItem = Roo.apply([], this.item);
1924         
1925         if(btn && btn.name == 'cancel'){
1926             this.tickItems = Roo.apply([], this.item);
1927             this.collapse();
1928             return;
1929         }
1930         
1931         this.clearItem();
1932         
1933         var _this = this;
1934         
1935         Roo.each(this.tickItems, function(o){
1936             _this.addItem(o);
1937         });
1938         
1939         this.collapse();
1940         
1941     },
1942     
1943     validate : function()
1944     {
1945         var v = this.getRawValue();
1946         
1947         if(this.multiple){
1948             v = this.getValue();
1949         }
1950         
1951         if(this.disabled || this.allowBlank || v.length){
1952             this.markValid();
1953             return true;
1954         }
1955         
1956         this.markInvalid();
1957         return false;
1958     },
1959     
1960     tickableInputEl : function()
1961     {
1962         if(!this.tickable || !this.editable){
1963             return this.inputEl();
1964         }
1965         
1966         return this.inputEl().select('.select2-search-field-input', true).first();
1967     },
1968     
1969     
1970     getAutoCreateTouchView : function()
1971     {
1972         var id = Roo.id();
1973         
1974         var cfg = {
1975             cls: 'form-group' //input-group
1976         };
1977         
1978         var input =  {
1979             tag: 'input',
1980             id : id,
1981             type : this.inputType,
1982             cls : 'form-control x-combo-noedit',
1983             autocomplete: 'new-password',
1984             placeholder : this.placeholder || '',
1985             readonly : true
1986         };
1987         
1988         if (this.name) {
1989             input.name = this.name;
1990         }
1991         
1992         if (this.size) {
1993             input.cls += ' input-' + this.size;
1994         }
1995         
1996         if (this.disabled) {
1997             input.disabled = true;
1998         }
1999         
2000         var inputblock = {
2001             cls : '',
2002             cn : [
2003                 input
2004             ]
2005         };
2006         
2007         if(this.before){
2008             inputblock.cls += ' input-group';
2009             
2010             inputblock.cn.unshift({
2011                 tag :'span',
2012                 cls : 'input-group-addon',
2013                 html : this.before
2014             });
2015         }
2016         
2017         if(this.removable && !this.multiple){
2018             inputblock.cls += ' roo-removable';
2019             
2020             inputblock.cn.push({
2021                 tag: 'button',
2022                 html : 'x',
2023                 cls : 'roo-combo-removable-btn close'
2024             });
2025         }
2026
2027         if(this.hasFeedback && !this.allowBlank){
2028             
2029             inputblock.cls += ' has-feedback';
2030             
2031             inputblock.cn.push({
2032                 tag: 'span',
2033                 cls: 'glyphicon form-control-feedback'
2034             });
2035             
2036         }
2037         
2038         if (this.after) {
2039             
2040             inputblock.cls += (this.before) ? '' : ' input-group';
2041             
2042             inputblock.cn.push({
2043                 tag :'span',
2044                 cls : 'input-group-addon',
2045                 html : this.after
2046             });
2047         }
2048
2049         var box = {
2050             tag: 'div',
2051             cn: [
2052                 {
2053                     tag: 'input',
2054                     type : 'hidden',
2055                     cls: 'form-hidden-field'
2056                 },
2057                 inputblock
2058             ]
2059             
2060         };
2061         
2062         if(this.multiple){
2063             box = {
2064                 tag: 'div',
2065                 cn: [
2066                     {
2067                         tag: 'input',
2068                         type : 'hidden',
2069                         cls: 'form-hidden-field'
2070                     },
2071                     {
2072                         tag: 'ul',
2073                         cls: 'select2-choices',
2074                         cn:[
2075                             {
2076                                 tag: 'li',
2077                                 cls: 'select2-search-field',
2078                                 cn: [
2079
2080                                     inputblock
2081                                 ]
2082                             }
2083                         ]
2084                     }
2085                 ]
2086             }
2087         };
2088         
2089         var combobox = {
2090             cls: 'select2-container input-group',
2091             cn: [
2092                 box
2093             ]
2094         };
2095         
2096         if(this.multiple){
2097             combobox.cls += ' select2-container-multi';
2098         }
2099         
2100         var align = this.labelAlign || this.parentLabelAlign();
2101         
2102         cfg.cn = combobox;
2103         
2104         if(this.fieldLabel.length){
2105             
2106             var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2107             var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2108             
2109             cfg.cn = [
2110                 {
2111                     tag: 'label',
2112                     cls : 'control-label ' + lw,
2113                     html : this.fieldLabel
2114
2115                 },
2116                 {
2117                     cls : cw, 
2118                     cn: [
2119                         combobox
2120                     ]
2121                 }
2122             ];
2123         }
2124         
2125         var settings = this;
2126         
2127         ['xs','sm','md','lg'].map(function(size){
2128             if (settings[size]) {
2129                 cfg.cls += ' col-' + size + '-' + settings[size];
2130             }
2131         });
2132         
2133         return cfg;
2134     },
2135     
2136     initTouchView : function()
2137     {
2138         this.renderTouchView();
2139         
2140         this.touchViewEl.on('scroll', function(){
2141             this.el.dom.scrollTop = 0;
2142         }, this);
2143         
2144         this.inputEl().on("click", this.showTouchView, this);
2145         this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2146         this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2147         
2148         this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2149         
2150         this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2151         this.store.on('load', this.onTouchViewLoad, this);
2152         this.store.on('loadexception', this.onTouchViewLoadException, this);
2153         
2154         if(this.hiddenName){
2155             
2156             this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2157             
2158             this.hiddenField.dom.value =
2159                 this.hiddenValue !== undefined ? this.hiddenValue :
2160                 this.value !== undefined ? this.value : '';
2161         
2162             this.el.dom.removeAttribute('name');
2163             this.hiddenField.dom.setAttribute('name', this.hiddenName);
2164         }
2165         
2166         if(this.multiple){
2167             this.choices = this.el.select('ul.select2-choices', true).first();
2168             this.searchField = this.el.select('ul li.select2-search-field', true).first();
2169         }
2170         
2171         if(this.removable && !this.multiple){
2172             var close = this.closeTriggerEl();
2173             if(close){
2174                 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2175                 close.on('click', this.removeBtnClick, this, close);
2176             }
2177         }
2178         
2179         return;
2180         
2181         
2182     },
2183     
2184     renderTouchView : function()
2185     {
2186         this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2187         this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2188         
2189         this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2190         this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2191         
2192         this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2193         this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2194         this.touchViewBodyEl.setStyle('overflow', 'auto');
2195         
2196         this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2197         this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2198         
2199         this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2200         this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2201         
2202     },
2203     
2204     showTouchView : function()
2205     {
2206         this.touchViewHeaderEl.hide();
2207
2208         if(this.fieldLabel.length){
2209             this.touchViewHeaderEl.dom.innerHTML = this.fieldLabel;
2210             this.touchViewHeaderEl.show();
2211         }
2212
2213         this.touchViewEl.show();
2214
2215         this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2216         this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2217
2218         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2219
2220         if(this.fieldLabel.length){
2221             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2222         }
2223         
2224         this.touchViewBodyEl.setHeight(bodyHeight);
2225
2226         if(this.animate){
2227             var _this = this;
2228             (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2229         }else{
2230             this.touchViewEl.addClass('in');
2231         }
2232
2233         this.doTouchViewQuery();
2234         
2235     },
2236     
2237     hideTouchView : function()
2238     {
2239         this.touchViewEl.removeClass('in');
2240
2241         if(this.animate){
2242             var _this = this;
2243             (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2244         }else{
2245             this.touchViewEl.setStyle('display', 'none');
2246         }
2247         
2248     },
2249     
2250     setTouchViewValue : function()
2251     {
2252         if(this.multiple){
2253             this.clearItem();
2254         
2255             var _this = this;
2256
2257             Roo.each(this.tickItems, function(o){
2258                 this.addItem(o);
2259             }, this);
2260         }
2261         
2262         this.hideTouchView();
2263     },
2264     
2265     doTouchViewQuery : function()
2266     {
2267         var qe = {
2268             query: '',
2269             forceAll: true,
2270             combo: this,
2271             cancel:false
2272         };
2273         
2274         if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2275             return false;
2276         }
2277         
2278         if(!this.alwaysQuery || this.mode == 'local'){
2279             this.onTouchViewLoad();
2280             return;
2281         }
2282         
2283         this.store.load();
2284     },
2285     
2286     onTouchViewBeforeLoad : function(combo,opts)
2287     {
2288         return;
2289     },
2290
2291     // private
2292     onTouchViewLoad : function()
2293     {
2294         if(this.store.getCount() < 1){
2295             this.onTouchViewEmptyResults();
2296             return;
2297         }
2298         
2299         this.clearTouchView();
2300         
2301         var rawValue = this.getRawValue();
2302         
2303         var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2304         
2305         this.tickItems = [];
2306         
2307         this.store.data.each(function(d, rowIndex){
2308             var row = this.touchViewListGroup.createChild(template);
2309             
2310             if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2311                 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = d.data[this.displayField];
2312             }
2313             
2314             if(!this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue()){
2315                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2316             }
2317             
2318             if(this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1){
2319                 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2320                 this.tickItems.push(d.data);
2321             }
2322             
2323             row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2324             
2325         }, this);
2326         
2327         var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2328         
2329         var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2330
2331         if(this.fieldLabel.length){
2332             bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2333         }
2334
2335         var listHeight = this.touchViewListGroup.getHeight();
2336         
2337         var _this = this;
2338         
2339         if(firstChecked && listHeight > bodyHeight){
2340             (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2341         }
2342         
2343     },
2344     
2345     onTouchViewLoadException : function()
2346     {
2347         this.hideTouchView();
2348     },
2349     
2350     onTouchViewEmptyResults : function()
2351     {
2352         this.clearTouchView();
2353         
2354         this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2355         
2356         this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2357         
2358     },
2359     
2360     clearTouchView : function()
2361     {
2362         this.touchViewListGroup.dom.innerHTML = '';
2363     },
2364     
2365     onTouchViewClick : function(e, el, o)
2366     {
2367         e.preventDefault();
2368         
2369         var row = o.row;
2370         var rowIndex = o.rowIndex;
2371         
2372         var r = this.store.getAt(rowIndex);
2373         
2374         if(!this.multiple){
2375             Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2376                 c.dom.removeAttribute('checked');
2377             }, this);
2378             
2379             row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2380         
2381             this.setFromData(r.data);
2382             
2383             var close = this.closeTriggerEl();
2384         
2385             if(close){
2386                 close.show();
2387             }
2388
2389             this.hideTouchView();
2390             
2391             this.fireEvent('select', this, r, rowIndex);
2392             
2393             return;
2394         }
2395         
2396         if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2397             row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2398             this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2399             return;
2400         }
2401         
2402         row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2403         this.addItem(r.data);
2404         this.tickItems.push(r.data);
2405         
2406     }
2407     
2408
2409     /** 
2410     * @cfg {Boolean} grow 
2411     * @hide 
2412     */
2413     /** 
2414     * @cfg {Number} growMin 
2415     * @hide 
2416     */
2417     /** 
2418     * @cfg {Number} growMax 
2419     * @hide 
2420     */
2421     /**
2422      * @hide
2423      * @method autoSize
2424      */
2425 });
2426
2427 Roo.apply(Roo.bootstrap.ComboBox,  {
2428     
2429     header : {
2430         tag: 'div',
2431         cls: 'modal-header',
2432         cn: [
2433             {
2434                 tag: 'h4',
2435                 cls: 'modal-title'
2436             }
2437         ]
2438     },
2439     
2440     body : {
2441         tag: 'div',
2442         cls: 'modal-body',
2443         cn: [
2444             {
2445                 tag: 'ul',
2446                 cls: 'list-group'
2447             }
2448         ]
2449     },
2450     
2451     listItemRadio : {
2452         tag: 'li',
2453         cls: 'list-group-item',
2454         cn: [
2455             {
2456                 tag: 'span',
2457                 cls: 'roo-combobox-list-group-item-value'
2458             },
2459             {
2460                 tag: 'div',
2461                 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2462                 cn: [
2463                     {
2464                         tag: 'input',
2465                         type: 'radio'
2466                     },
2467                     {
2468                         tag: 'label'
2469                     }
2470                 ]
2471             }
2472         ]
2473     },
2474     
2475     listItemCheckbox : {
2476         tag: 'li',
2477         cls: 'list-group-item',
2478         cn: [
2479             {
2480                 tag: 'span',
2481                 cls: 'roo-combobox-list-group-item-value'
2482             },
2483             {
2484                 tag: 'div',
2485                 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2486                 cn: [
2487                     {
2488                         tag: 'input',
2489                         type: 'checkbox'
2490                     },
2491                     {
2492                         tag: 'label'
2493                     }
2494                 ]
2495             }
2496         ]
2497     },
2498     
2499     emptyResult : {
2500         tag: 'div',
2501         cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2502     },
2503     
2504     footer : {
2505         tag: 'div',
2506         cls: 'modal-footer',
2507         cn: [
2508             {
2509                 tag: 'div',
2510                 cls: 'row',
2511                 cn: [
2512                     {
2513                         tag: 'div',
2514                         cls: 'col-xs-6 text-left',
2515                         cn: {
2516                             tag: 'button',
2517                             cls: 'btn btn-danger roo-touch-view-cancel',
2518                             html: 'Cancel'
2519                         }
2520                     },
2521                     {
2522                         tag: 'div',
2523                         cls: 'col-xs-6 text-right',
2524                         cn: {
2525                             tag: 'button',
2526                             cls: 'btn btn-success roo-touch-view-ok',
2527                             html: 'OK'
2528                         }
2529                     }
2530                 ]
2531             }
2532         ]
2533         
2534     }
2535 });
2536
2537 Roo.apply(Roo.bootstrap.ComboBox,  {
2538     
2539     touchViewTemplate : {
2540         tag: 'div',
2541         cls: 'modal fade roo-combobox-touch-view',
2542         cn: [
2543             {
2544                 tag: 'div',
2545                 cls: 'modal-dialog',
2546                 cn: [
2547                     {
2548                         tag: 'div',
2549                         cls: 'modal-content',
2550                         cn: [
2551                             Roo.bootstrap.ComboBox.header,
2552                             Roo.bootstrap.ComboBox.body,
2553                             Roo.bootstrap.ComboBox.footer
2554                         ]
2555                     }
2556                 ]
2557             }
2558         ]
2559     }
2560 });