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'
20 * Create a new ComboBox.
21 * @param {Object} config Configuration options
23 Roo.bootstrap.ComboBox = function(config){
24 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
28 * Fires when the dropdown list is expanded
29 * @param {Roo.bootstrap.ComboBox} combo This combo box
34 * Fires when the dropdown list is collapsed
35 * @param {Roo.bootstrap.ComboBox} combo This combo box
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
45 'beforeselect' : true,
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
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
67 * Fires when the 'add' icon is pressed (add a listener to enable add button)
68 * @param {Roo.bootstrap.ComboBox} combo This combo box
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)
80 * Fires when the remove value from the combobox array
81 * @param {Roo.bootstrap.ComboBox} combo This combo box
85 * @event specialfilter
86 * Fires when specialfilter
87 * @param {Roo.bootstrap.ComboBox} combo This combo box
89 'specialfilter' : true,
92 * Fires when tick the element
93 * @param {Roo.bootstrap.ComboBox} combo This combo box
97 * @event touchviewdisplay
98 * Fires when touch view require special display (default is using displayField)
99 * @param {Roo.bootstrap.ComboBox} combo This combo box
100 * @param {Object} cfg set html .
102 'touchviewdisplay' : true
109 this.selectedIndex = -1;
110 if(this.mode == 'local'){
111 if(config.queryDelay === undefined){
112 this.queryDelay = 10;
114 if(config.minChars === undefined){
120 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
123 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
124 * rendering into an Roo.Editor, defaults to false)
127 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
128 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
131 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
134 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
135 * the dropdown list (defaults to undefined, with no header element)
139 * @cfg {String/Roo.Template} tpl The template to use to render the output
143 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
145 listWidth: undefined,
147 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
148 * mode = 'remote' or 'text' if mode = 'local')
150 displayField: undefined,
153 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
154 * mode = 'remote' or 'value' if mode = 'local').
155 * Note: use of a valueField requires the user make a selection
156 * in order for a value to be mapped.
158 valueField: undefined,
162 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
163 * field's data value (defaults to the underlying DOM element's name)
165 hiddenName: undefined,
167 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
171 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
173 selectedClass: 'active',
176 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
180 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
181 * anchor positions (defaults to 'tl-bl')
185 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
189 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
190 * query specified by the allQuery config option (defaults to 'query')
192 triggerAction: 'query',
194 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
195 * (defaults to 4, does not apply if editable = false)
199 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
200 * delay (typeAheadDelay) if it matches a known value (defaults to false)
204 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
205 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
209 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
210 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
214 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
215 * when editable = true (defaults to false)
219 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
223 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
224 * when mode = 'remote' (defaults to 'Loading...')
226 loadingText: 'Loading...',
228 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
232 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
236 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
237 * traditional select (defaults to true)
241 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
245 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
249 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
250 * listWidth has a higher value)
254 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
255 * allow the user to set arbitrary text into the field (defaults to false)
257 forceSelection:false,
259 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
260 * if typeAhead = true (defaults to 250)
262 typeAheadDelay : 250,
264 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
265 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
267 valueNotFoundText : undefined,
269 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
274 * @cfg {Boolean} disableClear Disable showing of clear button.
276 disableClear : false,
278 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
283 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
288 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
290 invalidClass : "has-warning",
293 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
295 validClass : "has-success",
298 * @cfg {Boolean} specialFilter (true|false) special filter default false
300 specialFilter : false,
303 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
305 mobileTouchView : true,
317 btnPosition : 'right',
319 showToggleBtn : true,
321 emptyResultText: 'Empty',
322 triggerText : 'Select',
324 // element that contains real text value.. (when hidden is used..)
326 getAutoCreate : function()
334 if(Roo.isTouch && this.mobileTouchView){
335 cfg = this.getAutoCreateTouchView();
343 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
348 * ComboBox with tickable selections
351 var align = this.labelAlign || this.parentLabelAlign();
354 cls : 'form-group roo-combobox-tickable' //input-group
359 cls : 'tickable-buttons',
364 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
365 html : this.triggerText
371 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
378 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
387 cls: 'select2-search-field-input'
393 Roo.each(buttons.cn, function(c){
395 c.cls += ' btn-' + _this.size;
398 if (_this.disabled) {
409 cls: 'form-hidden-field'
413 cls: 'select2-choices',
417 cls: 'select2-search-field',
429 cls: 'select2-container input-group select2-container-multi',
434 // cls: 'typeahead typeahead-long dropdown-menu',
435 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
440 if(this.hasFeedback && !this.allowBlank){
444 cls: 'glyphicon form-control-feedback'
447 combobox.cn.push(feedback);
450 if (align ==='left' && this.fieldLabel.length) {
452 Roo.log("left and has label");
458 cls : 'control-label col-sm-' + this.labelWidth,
459 html : this.fieldLabel
463 cls : "col-sm-" + (12 - this.labelWidth),
470 } else if ( this.fieldLabel.length) {
476 //cls : 'input-group-addon',
477 html : this.fieldLabel
487 Roo.log(" no label && no align");
494 ['xs','sm','md','lg'].map(function(size){
495 if (settings[size]) {
496 cfg.cls += ' col-' + size + '-' + settings[size];
504 _initEventsCalled : false,
507 initEvents: function()
510 if (this._initEventsCalled) { // as we call render... prevent looping...
513 this._initEventsCalled = true;
516 throw "can not find store for combo";
519 this.store = Roo.factory(this.store, Roo.data);
521 // if we are building from html. then this element is so complex, that we can not really
522 // use the rendered HTML.
523 // so we have to trash and replace the previous code.
524 if (Roo.XComponent.build_from_html) {
526 // remove this element....
527 var e = this.el.dom, k=0;
528 while (e ) { e = e.previousSibling; ++k;}
533 this.rendered = false;
535 this.render(this.parent().getChildContainer(true), k);
546 if(Roo.isTouch && this.mobileTouchView){
547 this.initTouchView();
552 this.initTickableEvents();
556 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
560 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
562 this.hiddenField.dom.value =
563 this.hiddenValue !== undefined ? this.hiddenValue :
564 this.value !== undefined ? this.value : '';
566 // prevent input submission
567 this.el.dom.removeAttribute('name');
568 this.hiddenField.dom.setAttribute('name', this.hiddenName);
573 // this.el.dom.setAttribute('autocomplete', 'off');
576 var cls = 'x-combo-list';
578 //this.list = new Roo.Layer({
579 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
585 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
586 _this.list.setWidth(lw);
589 this.list.on('mouseover', this.onViewOver, this);
590 this.list.on('mousemove', this.onViewMove, this);
592 this.list.on('scroll', this.onViewScroll, this);
595 this.list.swallowEvent('mousewheel');
596 this.assetHeight = 0;
599 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
600 this.assetHeight += this.header.getHeight();
603 this.innerList = this.list.createChild({cls:cls+'-inner'});
604 this.innerList.on('mouseover', this.onViewOver, this);
605 this.innerList.on('mousemove', this.onViewMove, this);
606 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
608 if(this.allowBlank && !this.pageSize && !this.disableClear){
609 this.footer = this.list.createChild({cls:cls+'-ft'});
610 this.pageTb = new Roo.Toolbar(this.footer);
614 this.footer = this.list.createChild({cls:cls+'-ft'});
615 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
616 {pageSize: this.pageSize});
620 if (this.pageTb && this.allowBlank && !this.disableClear) {
622 this.pageTb.add(new Roo.Toolbar.Fill(), {
623 cls: 'x-btn-icon x-btn-clear',
629 _this.onSelect(false, -1);
634 this.assetHeight += this.footer.getHeight();
639 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
642 this.view = new Roo.View(this.list, this.tpl, {
643 singleSelect:true, store: this.store, selectedClass: this.selectedClass
645 //this.view.wrapEl.setDisplayed(false);
646 this.view.on('click', this.onViewClick, this);
650 this.store.on('beforeload', this.onBeforeLoad, this);
651 this.store.on('load', this.onLoad, this);
652 this.store.on('loadexception', this.onLoadException, this);
655 this.resizer = new Roo.Resizable(this.list, {
656 pinned:true, handles:'se'
658 this.resizer.on('resize', function(r, w, h){
659 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
661 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
662 this.restrictHeight();
664 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
668 this.editable = true;
669 this.setEditable(false);
674 if (typeof(this.events.add.listeners) != 'undefined') {
676 this.addicon = this.wrap.createChild(
677 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
679 this.addicon.on('click', function(e) {
680 this.fireEvent('add', this);
683 if (typeof(this.events.edit.listeners) != 'undefined') {
685 this.editicon = this.wrap.createChild(
686 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
688 this.editicon.setStyle('margin-left', '40px');
690 this.editicon.on('click', function(e) {
692 // we fire even if inothing is selected..
693 this.fireEvent('edit', this, this.lastData );
699 this.keyNav = new Roo.KeyNav(this.inputEl(), {
701 this.inKeyMode = true;
705 "down" : function(e){
706 if(!this.isExpanded()){
707 this.onTriggerClick();
709 this.inKeyMode = true;
714 "enter" : function(e){
715 // this.onViewClick();
719 if(this.fireEvent("specialkey", this, e)){
720 this.onViewClick(false);
733 if(this.fireEvent("specialkey", this, e)){
734 this.onViewClick(false);
742 doRelay : function(foo, bar, hname){
743 if(hname == 'down' || this.scope.isExpanded()){
744 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
753 this.queryDelay = Math.max(this.queryDelay || 10,
754 this.mode == 'local' ? 10 : 250);
757 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
760 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
762 if(this.editable !== false){
763 this.inputEl().on("keyup", this.onKeyUp, this);
765 if(this.forceSelection){
766 this.inputEl().on('blur', this.doForce, this);
770 this.choices = this.el.select('ul.select2-choices', true).first();
771 this.searchField = this.el.select('ul li.select2-search-field', true).first();
775 initTickableEvents: function()
781 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
783 this.hiddenField.dom.value =
784 this.hiddenValue !== undefined ? this.hiddenValue :
785 this.value !== undefined ? this.value : '';
787 // prevent input submission
788 this.el.dom.removeAttribute('name');
789 this.hiddenField.dom.setAttribute('name', this.hiddenName);
794 // this.list = this.el.select('ul.dropdown-menu',true).first();
796 this.choices = this.el.select('ul.select2-choices', true).first();
797 this.searchField = this.el.select('ul li.select2-search-field', true).first();
798 if(this.triggerList){
799 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
802 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
803 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
805 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
806 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
808 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
809 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
811 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
812 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
813 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
816 this.cancelBtn.hide();
821 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
822 _this.list.setWidth(lw);
825 this.list.on('mouseover', this.onViewOver, this);
826 this.list.on('mousemove', this.onViewMove, this);
828 this.list.on('scroll', this.onViewScroll, this);
831 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>';
834 this.view = new Roo.View(this.list, this.tpl, {
835 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
838 //this.view.wrapEl.setDisplayed(false);
839 this.view.on('click', this.onViewClick, this);
843 this.store.on('beforeload', this.onBeforeLoad, this);
844 this.store.on('load', this.onLoad, this);
845 this.store.on('loadexception', this.onLoadException, this);
848 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
850 this.inKeyMode = true;
854 "down" : function(e){
855 this.inKeyMode = true;
859 "enter" : function(e){
860 if(this.fireEvent("specialkey", this, e)){
861 this.onViewClick(false);
868 this.onTickableFooterButtonClick(e, false, false);
872 this.fireEvent("specialkey", this, e);
874 this.onTickableFooterButtonClick(e, false, false);
881 doRelay : function(e, fn, key){
882 if(this.scope.isExpanded()){
883 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
892 this.queryDelay = Math.max(this.queryDelay || 10,
893 this.mode == 'local' ? 10 : 250);
896 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
899 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
902 if(this.editable !== false){
903 this.tickableInputEl().on("keyup", this.onKeyUp, this);
908 onDestroy : function(){
910 this.view.setStore(null);
911 this.view.el.removeAllListeners();
912 this.view.el.remove();
913 this.view.purgeListeners();
916 this.list.dom.innerHTML = '';
920 this.store.un('beforeload', this.onBeforeLoad, this);
921 this.store.un('load', this.onLoad, this);
922 this.store.un('loadexception', this.onLoadException, this);
924 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
928 fireKey : function(e){
929 if(e.isNavKeyPress() && !this.list.isVisible()){
930 this.fireEvent("specialkey", this, e);
935 onResize: function(w, h){
936 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
938 // if(typeof w != 'number'){
939 // // we do not handle it!?!?
942 // var tw = this.trigger.getWidth();
943 // // tw += this.addicon ? this.addicon.getWidth() : 0;
944 // // tw += this.editicon ? this.editicon.getWidth() : 0;
946 // this.inputEl().setWidth( this.adjustWidth('input', x));
948 // //this.trigger.setStyle('left', x+'px');
950 // if(this.list && this.listWidth === undefined){
951 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
952 // this.list.setWidth(lw);
953 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
961 * Allow or prevent the user from directly editing the field text. If false is passed,
962 * the user will only be able to select from the items defined in the dropdown list. This method
963 * is the runtime equivalent of setting the 'editable' config option at config time.
964 * @param {Boolean} value True to allow the user to directly edit the field text
966 setEditable : function(value){
967 if(value == this.editable){
970 this.editable = value;
972 this.inputEl().dom.setAttribute('readOnly', true);
973 this.inputEl().on('mousedown', this.onTriggerClick, this);
974 this.inputEl().addClass('x-combo-noedit');
976 this.inputEl().dom.setAttribute('readOnly', false);
977 this.inputEl().un('mousedown', this.onTriggerClick, this);
978 this.inputEl().removeClass('x-combo-noedit');
984 onBeforeLoad : function(combo,opts){
989 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
991 this.restrictHeight();
992 this.selectedIndex = -1;
998 this.hasQuery = false;
1004 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1005 this.loading.hide();
1008 if(this.store.getCount() > 0){
1010 this.restrictHeight();
1011 if(this.lastQuery == this.allQuery){
1012 if(this.editable && !this.tickable){
1013 this.inputEl().dom.select();
1017 !this.selectByValue(this.value, true) &&
1020 !this.store.lastOptions ||
1021 typeof(this.store.lastOptions.add) == 'undefined' ||
1022 this.store.lastOptions.add != true
1025 this.select(0, true);
1031 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1032 this.taTask.delay(this.typeAheadDelay);
1036 this.onEmptyResults();
1042 onLoadException : function()
1044 this.hasQuery = false;
1046 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1047 this.loading.hide();
1050 if(this.tickable && this.editable){
1055 // only causes errors at present
1056 //Roo.log(this.store.reader.jsonData);
1057 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1059 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1065 onTypeAhead : function(){
1066 if(this.store.getCount() > 0){
1067 var r = this.store.getAt(0);
1068 var newValue = r.data[this.displayField];
1069 var len = newValue.length;
1070 var selStart = this.getRawValue().length;
1072 if(selStart != len){
1073 this.setRawValue(newValue);
1074 this.selectText(selStart, newValue.length);
1080 onSelect : function(record, index){
1082 if(this.fireEvent('beforeselect', this, record, index) !== false){
1084 this.setFromData(index > -1 ? record.data : false);
1087 this.fireEvent('select', this, record, index);
1092 * Returns the currently selected field value or empty string if no value is set.
1093 * @return {String} value The selected value
1095 getValue : function(){
1098 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1101 if(this.valueField){
1102 return typeof this.value != 'undefined' ? this.value : '';
1104 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1109 * Clears any text/value currently set in the field
1111 clearValue : function(){
1112 if(this.hiddenField){
1113 this.hiddenField.dom.value = '';
1116 this.setRawValue('');
1117 this.lastSelectionText = '';
1118 this.lastData = false;
1120 var close = this.closeTriggerEl();
1129 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1130 * will be displayed in the field. If the value does not match the data value of an existing item,
1131 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1132 * Otherwise the field will be blank (although the value will still be set).
1133 * @param {String} value The value to match
1135 setValue : function(v){
1142 if(this.valueField){
1143 var r = this.findRecord(this.valueField, v);
1145 text = r.data[this.displayField];
1146 }else if(this.valueNotFoundText !== undefined){
1147 text = this.valueNotFoundText;
1150 this.lastSelectionText = text;
1151 if(this.hiddenField){
1152 this.hiddenField.dom.value = v;
1154 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1157 var close = this.closeTriggerEl();
1160 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1164 * @property {Object} the last set data for the element
1169 * Sets the value of the field based on a object which is related to the record format for the store.
1170 * @param {Object} value the value to set as. or false on reset?
1172 setFromData : function(o){
1179 var dv = ''; // display value
1180 var vv = ''; // value value..
1182 if (this.displayField) {
1183 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1185 // this is an error condition!!!
1186 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1189 if(this.valueField){
1190 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1193 var close = this.closeTriggerEl();
1196 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1199 if(this.hiddenField){
1200 this.hiddenField.dom.value = vv;
1202 this.lastSelectionText = dv;
1203 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1207 // no hidden field.. - we store the value in 'value', but still display
1208 // display field!!!!
1209 this.lastSelectionText = dv;
1210 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1218 // overridden so that last data is reset..
1225 this.setValue(this.originalValue);
1226 this.clearInvalid();
1227 this.lastData = false;
1229 this.view.clearSelections();
1233 findRecord : function(prop, value){
1235 if(this.store.getCount() > 0){
1236 this.store.each(function(r){
1237 if(r.data[prop] == value){
1249 // returns hidden if it's set..
1250 if (!this.rendered) {return ''};
1251 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1255 onViewMove : function(e, t){
1256 this.inKeyMode = false;
1260 onViewOver : function(e, t){
1261 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1264 var item = this.view.findItemFromChild(t);
1267 var index = this.view.indexOf(item);
1268 this.select(index, false);
1273 onViewClick : function(view, doFocus, el, e)
1275 var index = this.view.getSelectedIndexes()[0];
1277 var r = this.store.getAt(index);
1281 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1288 Roo.each(this.tickItems, function(v,k){
1290 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1292 _this.tickItems.splice(k, 1);
1294 if(typeof(e) == 'undefined' && view == false){
1295 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1307 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1308 this.tickItems.push(r.data);
1311 if(typeof(e) == 'undefined' && view == false){
1312 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1319 this.onSelect(r, index);
1321 if(doFocus !== false && !this.blockFocus){
1322 this.inputEl().focus();
1327 restrictHeight : function(){
1328 //this.innerList.dom.style.height = '';
1329 //var inner = this.innerList.dom;
1330 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1331 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1332 //this.list.beginUpdate();
1333 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1334 this.list.alignTo(this.inputEl(), this.listAlign);
1335 this.list.alignTo(this.inputEl(), this.listAlign);
1336 //this.list.endUpdate();
1340 onEmptyResults : function(){
1342 if(this.tickable && this.editable){
1343 this.restrictHeight();
1351 * Returns true if the dropdown list is expanded, else false.
1353 isExpanded : function(){
1354 return this.list.isVisible();
1358 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1359 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1360 * @param {String} value The data value of the item to select
1361 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1362 * selected item if it is not currently in view (defaults to true)
1363 * @return {Boolean} True if the value matched an item in the list, else false
1365 selectByValue : function(v, scrollIntoView){
1366 if(v !== undefined && v !== null){
1367 var r = this.findRecord(this.valueField || this.displayField, v);
1369 this.select(this.store.indexOf(r), scrollIntoView);
1377 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1378 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1379 * @param {Number} index The zero-based index of the list item to select
1380 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1381 * selected item if it is not currently in view (defaults to true)
1383 select : function(index, scrollIntoView){
1384 this.selectedIndex = index;
1385 this.view.select(index);
1386 if(scrollIntoView !== false){
1387 var el = this.view.getNode(index);
1389 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1392 this.list.scrollChildIntoView(el, false);
1398 selectNext : function(){
1399 var ct = this.store.getCount();
1401 if(this.selectedIndex == -1){
1403 }else if(this.selectedIndex < ct-1){
1404 this.select(this.selectedIndex+1);
1410 selectPrev : function(){
1411 var ct = this.store.getCount();
1413 if(this.selectedIndex == -1){
1415 }else if(this.selectedIndex != 0){
1416 this.select(this.selectedIndex-1);
1422 onKeyUp : function(e){
1423 if(this.editable !== false && !e.isSpecialKey()){
1424 this.lastKey = e.getKey();
1425 this.dqTask.delay(this.queryDelay);
1430 validateBlur : function(){
1431 return !this.list || !this.list.isVisible();
1435 initQuery : function(){
1437 var v = this.getRawValue();
1439 if(this.tickable && this.editable){
1440 v = this.tickableInputEl().getValue();
1447 doForce : function(){
1448 if(this.inputEl().dom.value.length > 0){
1449 this.inputEl().dom.value =
1450 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1456 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1457 * query allowing the query action to be canceled if needed.
1458 * @param {String} query The SQL query to execute
1459 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1460 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1461 * saved in the current store (defaults to false)
1463 doQuery : function(q, forceAll){
1465 if(q === undefined || q === null){
1474 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1479 forceAll = qe.forceAll;
1480 if(forceAll === true || (q.length >= this.minChars)){
1482 this.hasQuery = true;
1484 if(this.lastQuery != q || this.alwaysQuery){
1486 if(this.mode == 'local'){
1487 this.selectedIndex = -1;
1489 this.store.clearFilter();
1492 if(this.specialFilter){
1493 this.fireEvent('specialfilter', this);
1498 this.store.filter(this.displayField, q);
1501 this.store.fireEvent("datachanged", this.store);
1508 this.store.baseParams[this.queryParam] = q;
1510 var options = {params : this.getParams(q)};
1514 options.params.start = this.page * this.pageSize;
1517 this.store.load(options);
1520 * this code will make the page width larger, at the beginning, the list not align correctly,
1521 * we should expand the list on onLoad
1527 this.selectedIndex = -1;
1532 this.loadNext = false;
1536 getParams : function(q){
1538 //p[this.queryParam] = q;
1542 p.limit = this.pageSize;
1548 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1550 collapse : function(){
1551 if(!this.isExpanded()){
1558 this.hasFocus = false;
1560 this.cancelBtn.hide();
1561 this.trigger.show();
1564 this.tickableInputEl().dom.value = '';
1565 this.tickableInputEl().blur();
1570 Roo.get(document).un('mousedown', this.collapseIf, this);
1571 Roo.get(document).un('mousewheel', this.collapseIf, this);
1572 if (!this.editable) {
1573 Roo.get(document).un('keydown', this.listKeyPress, this);
1575 this.fireEvent('collapse', this);
1579 collapseIf : function(e){
1580 var in_combo = e.within(this.el);
1581 var in_list = e.within(this.list);
1582 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1584 if (in_combo || in_list || is_list) {
1585 //e.stopPropagation();
1590 this.onTickableFooterButtonClick(e, false, false);
1598 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1600 expand : function(){
1602 if(this.isExpanded() || !this.hasFocus){
1606 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1607 this.list.setWidth(lw);
1614 this.restrictHeight();
1618 this.tickItems = Roo.apply([], this.item);
1621 this.cancelBtn.show();
1622 this.trigger.hide();
1625 this.tickableInputEl().focus();
1630 Roo.get(document).on('mousedown', this.collapseIf, this);
1631 Roo.get(document).on('mousewheel', this.collapseIf, this);
1632 if (!this.editable) {
1633 Roo.get(document).on('keydown', this.listKeyPress, this);
1636 this.fireEvent('expand', this);
1640 // Implements the default empty TriggerField.onTriggerClick function
1641 onTriggerClick : function(e)
1643 Roo.log('trigger click');
1645 if(this.disabled || !this.triggerList){
1650 this.loadNext = false;
1652 if(this.isExpanded()){
1654 if (!this.blockFocus) {
1655 this.inputEl().focus();
1659 this.hasFocus = true;
1660 if(this.triggerAction == 'all') {
1661 this.doQuery(this.allQuery, true);
1663 this.doQuery(this.getRawValue());
1665 if (!this.blockFocus) {
1666 this.inputEl().focus();
1671 onTickableTriggerClick : function(e)
1678 this.loadNext = false;
1679 this.hasFocus = true;
1681 if(this.triggerAction == 'all') {
1682 this.doQuery(this.allQuery, true);
1684 this.doQuery(this.getRawValue());
1688 onSearchFieldClick : function(e)
1690 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1691 this.onTickableFooterButtonClick(e, false, false);
1695 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1700 this.loadNext = false;
1701 this.hasFocus = true;
1703 if(this.triggerAction == 'all') {
1704 this.doQuery(this.allQuery, true);
1706 this.doQuery(this.getRawValue());
1710 listKeyPress : function(e)
1712 //Roo.log('listkeypress');
1713 // scroll to first matching element based on key pres..
1714 if (e.isSpecialKey()) {
1717 var k = String.fromCharCode(e.getKey()).toUpperCase();
1720 var csel = this.view.getSelectedNodes();
1721 var cselitem = false;
1723 var ix = this.view.indexOf(csel[0]);
1724 cselitem = this.store.getAt(ix);
1725 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1731 this.store.each(function(v) {
1733 // start at existing selection.
1734 if (cselitem.id == v.id) {
1740 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1741 match = this.store.indexOf(v);
1747 if (match === false) {
1748 return true; // no more action?
1751 this.view.select(match);
1752 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1753 sn.scrollIntoView(sn.dom.parentNode, false);
1756 onViewScroll : function(e, t){
1758 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){
1762 this.hasQuery = true;
1764 this.loading = this.list.select('.loading', true).first();
1766 if(this.loading === null){
1767 this.list.createChild({
1769 cls: 'loading select2-more-results select2-active',
1770 html: 'Loading more results...'
1773 this.loading = this.list.select('.loading', true).first();
1775 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1777 this.loading.hide();
1780 this.loading.show();
1785 this.loadNext = true;
1787 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1792 addItem : function(o)
1794 var dv = ''; // display value
1796 if (this.displayField) {
1797 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1799 // this is an error condition!!!
1800 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1807 var choice = this.choices.createChild({
1809 cls: 'select2-search-choice',
1818 cls: 'select2-search-choice-close',
1823 }, this.searchField);
1825 var close = choice.select('a.select2-search-choice-close', true).first();
1827 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1835 this.inputEl().dom.value = '';
1840 onRemoveItem : function(e, _self, o)
1844 this.lastItem = Roo.apply([], this.item);
1846 var index = this.item.indexOf(o.data) * 1;
1849 Roo.log('not this item?!');
1853 this.item.splice(index, 1);
1858 this.fireEvent('remove', this, e);
1864 syncValue : function()
1866 if(!this.item.length){
1873 Roo.each(this.item, function(i){
1874 if(_this.valueField){
1875 value.push(i[_this.valueField]);
1882 this.value = value.join(',');
1884 if(this.hiddenField){
1885 this.hiddenField.dom.value = this.value;
1888 this.store.fireEvent("datachanged", this.store);
1891 clearItem : function()
1899 Roo.each(this.choices.select('>li.select2-search-choice', true).elements, function(c){
1907 if(this.tickable && !Roo.isTouch){
1908 this.view.refresh();
1912 inputEl: function ()
1914 if(Roo.isTouch && this.mobileTouchView){
1915 return this.el.select('input.form-control',true).first();
1919 return this.searchField;
1922 return this.el.select('input.form-control',true).first();
1926 onTickableFooterButtonClick : function(e, btn, el)
1930 this.lastItem = Roo.apply([], this.item);
1932 if(btn && btn.name == 'cancel'){
1933 this.tickItems = Roo.apply([], this.item);
1942 Roo.each(this.tickItems, function(o){
1950 validate : function()
1952 var v = this.getRawValue();
1955 v = this.getValue();
1958 if(this.disabled || this.allowBlank || v.length){
1967 tickableInputEl : function()
1969 if(!this.tickable || !this.editable){
1970 return this.inputEl();
1973 return this.inputEl().select('.select2-search-field-input', true).first();
1977 getAutoCreateTouchView : function()
1982 cls: 'form-group' //input-group
1988 type : this.inputType,
1989 cls : 'form-control x-combo-noedit',
1990 autocomplete: 'new-password',
1991 placeholder : this.placeholder || '',
1996 input.name = this.name;
2000 input.cls += ' input-' + this.size;
2003 if (this.disabled) {
2004 input.disabled = true;
2015 inputblock.cls += ' input-group';
2017 inputblock.cn.unshift({
2019 cls : 'input-group-addon',
2024 if(this.removable && !this.multiple){
2025 inputblock.cls += ' roo-removable';
2027 inputblock.cn.push({
2030 cls : 'roo-combo-removable-btn close'
2034 if(this.hasFeedback && !this.allowBlank){
2036 inputblock.cls += ' has-feedback';
2038 inputblock.cn.push({
2040 cls: 'glyphicon form-control-feedback'
2047 inputblock.cls += (this.before) ? '' : ' input-group';
2049 inputblock.cn.push({
2051 cls : 'input-group-addon',
2062 cls: 'form-hidden-field'
2076 cls: 'form-hidden-field'
2080 cls: 'select2-choices',
2084 cls: 'select2-search-field',
2097 cls: 'select2-container input-group',
2104 combobox.cls += ' select2-container-multi';
2107 var align = this.labelAlign || this.parentLabelAlign();
2111 if(this.fieldLabel.length){
2113 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2114 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2119 cls : 'control-label ' + lw,
2120 html : this.fieldLabel
2132 var settings = this;
2134 ['xs','sm','md','lg'].map(function(size){
2135 if (settings[size]) {
2136 cfg.cls += ' col-' + size + '-' + settings[size];
2143 initTouchView : function()
2145 this.renderTouchView();
2147 this.touchViewEl.on('scroll', function(){
2148 this.el.dom.scrollTop = 0;
2151 this.inputEl().on("click", this.showTouchView, this);
2152 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2153 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2155 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2157 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2158 this.store.on('load', this.onTouchViewLoad, this);
2159 this.store.on('loadexception', this.onTouchViewLoadException, this);
2161 if(this.hiddenName){
2163 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2165 this.hiddenField.dom.value =
2166 this.hiddenValue !== undefined ? this.hiddenValue :
2167 this.value !== undefined ? this.value : '';
2169 this.el.dom.removeAttribute('name');
2170 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2174 this.choices = this.el.select('ul.select2-choices', true).first();
2175 this.searchField = this.el.select('ul li.select2-search-field', true).first();
2178 if(this.removable && !this.multiple){
2179 var close = this.closeTriggerEl();
2181 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2182 close.on('click', this.removeBtnClick, this, close);
2191 renderTouchView : function()
2193 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2194 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2196 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2197 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2199 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2200 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2201 this.touchViewBodyEl.setStyle('overflow', 'auto');
2203 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2204 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2206 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2207 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2211 showTouchView : function()
2213 this.touchViewHeaderEl.hide();
2215 if(this.fieldLabel.length){
2216 this.touchViewHeaderEl.dom.innerHTML = this.fieldLabel;
2217 this.touchViewHeaderEl.show();
2220 this.touchViewEl.show();
2222 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2223 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2225 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2227 if(this.fieldLabel.length){
2228 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2231 this.touchViewBodyEl.setHeight(bodyHeight);
2235 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2237 this.touchViewEl.addClass('in');
2240 this.doTouchViewQuery();
2244 hideTouchView : function()
2246 this.touchViewEl.removeClass('in');
2250 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2252 this.touchViewEl.setStyle('display', 'none');
2257 setTouchViewValue : function()
2264 Roo.each(this.tickItems, function(o){
2269 this.hideTouchView();
2272 doTouchViewQuery : function()
2281 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2285 if(!this.alwaysQuery || this.mode == 'local'){
2286 this.onTouchViewLoad();
2293 onTouchViewBeforeLoad : function(combo,opts)
2299 onTouchViewLoad : function()
2301 if(this.store.getCount() < 1){
2302 this.onTouchViewEmptyResults();
2306 this.clearTouchView();
2308 var rawValue = this.getRawValue();
2310 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2312 this.tickItems = [];
2314 this.store.data.each(function(d, rowIndex){
2315 var row = this.touchViewListGroup.createChild(template);
2317 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2319 html : d.data[this.displayField]
2322 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2323 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2327 if(!this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue()){
2328 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2331 if(this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1){
2332 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2333 this.tickItems.push(d.data);
2336 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2340 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2342 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2344 if(this.fieldLabel.length){
2345 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2348 var listHeight = this.touchViewListGroup.getHeight();
2352 if(firstChecked && listHeight > bodyHeight){
2353 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2358 onTouchViewLoadException : function()
2360 this.hideTouchView();
2363 onTouchViewEmptyResults : function()
2365 this.clearTouchView();
2367 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2369 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2373 clearTouchView : function()
2375 this.touchViewListGroup.dom.innerHTML = '';
2378 onTouchViewClick : function(e, el, o)
2383 var rowIndex = o.rowIndex;
2385 var r = this.store.getAt(rowIndex);
2388 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2389 c.dom.removeAttribute('checked');
2392 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2394 this.setFromData(r.data);
2396 var close = this.closeTriggerEl();
2402 this.hideTouchView();
2404 this.fireEvent('select', this, r, rowIndex);
2409 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2410 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2411 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2415 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2416 this.addItem(r.data);
2417 this.tickItems.push(r.data);
2423 * @cfg {Boolean} grow
2427 * @cfg {Number} growMin
2431 * @cfg {Number} growMax
2440 Roo.apply(Roo.bootstrap.ComboBox, {
2444 cls: 'modal-header',
2466 cls: 'list-group-item',
2470 cls: 'roo-combobox-list-group-item-value'
2474 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2488 listItemCheckbox : {
2490 cls: 'list-group-item',
2494 cls: 'roo-combobox-list-group-item-value'
2498 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2514 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2519 cls: 'modal-footer',
2527 cls: 'col-xs-6 text-left',
2530 cls: 'btn btn-danger roo-touch-view-cancel',
2536 cls: 'col-xs-6 text-right',
2539 cls: 'btn btn-success roo-touch-view-ok',
2550 Roo.apply(Roo.bootstrap.ComboBox, {
2552 touchViewTemplate : {
2554 cls: 'modal fade roo-combobox-touch-view',
2558 cls: 'modal-dialog',
2562 cls: 'modal-content',
2564 Roo.bootstrap.ComboBox.header,
2565 Roo.bootstrap.ComboBox.body,
2566 Roo.bootstrap.ComboBox.footer