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
102 this.selectedIndex = -1;
103 if(this.mode == 'local'){
104 if(config.queryDelay === undefined){
105 this.queryDelay = 10;
107 if(config.minChars === undefined){
113 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
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)
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"})
124 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
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)
132 * @cfg {String/Roo.Template} tpl The template to use to render the output
136 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
138 listWidth: undefined,
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')
143 displayField: undefined,
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.
151 valueField: undefined,
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)
158 hiddenName: undefined,
160 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
164 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
166 selectedClass: 'active',
169 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
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')
178 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
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')
185 triggerAction: 'query',
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)
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)
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')
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)
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)
212 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
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...')
219 loadingText: 'Loading...',
221 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
225 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
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)
234 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
238 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
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)
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)
250 forceSelection:false,
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)
255 typeAheadDelay : 250,
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)
260 valueNotFoundText : undefined,
262 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
267 * @cfg {Boolean} disableClear Disable showing of clear button.
269 disableClear : false,
271 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
276 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
281 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
283 invalidClass : "has-warning",
286 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
288 validClass : "has-success",
291 * @cfg {Boolean} specialFilter (true|false) special filter default false
293 specialFilter : false,
296 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
298 mobileTouchView : true,
310 btnPosition : 'right',
312 showToggleBtn : true,
314 emptyResultText: 'Empty',
315 triggerText : 'Select',
317 // element that contains real text value.. (when hidden is used..)
319 getAutoCreate : function()
327 if(Roo.isTouch && this.mobileTouchView){
328 cfg = this.getAutoCreateTouchView();
336 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
341 * ComboBox with tickable selections
344 var align = this.labelAlign || this.parentLabelAlign();
347 cls : 'form-group roo-combobox-tickable' //input-group
352 cls : 'tickable-buttons',
357 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
358 html : this.triggerText
364 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
371 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
380 cls: 'select2-search-field-input'
386 Roo.each(buttons.cn, function(c){
388 c.cls += ' btn-' + _this.size;
391 if (_this.disabled) {
402 cls: 'form-hidden-field'
406 cls: 'select2-choices',
410 cls: 'select2-search-field',
422 cls: 'select2-container input-group select2-container-multi',
427 // cls: 'typeahead typeahead-long dropdown-menu',
428 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
433 if(this.hasFeedback && !this.allowBlank){
437 cls: 'glyphicon form-control-feedback'
440 combobox.cn.push(feedback);
443 if (align ==='left' && this.fieldLabel.length) {
445 Roo.log("left and has label");
451 cls : 'control-label col-sm-' + this.labelWidth,
452 html : this.fieldLabel
456 cls : "col-sm-" + (12 - this.labelWidth),
463 } else if ( this.fieldLabel.length) {
469 //cls : 'input-group-addon',
470 html : this.fieldLabel
480 Roo.log(" no label && no align");
487 ['xs','sm','md','lg'].map(function(size){
488 if (settings[size]) {
489 cfg.cls += ' col-' + size + '-' + settings[size];
497 _initEventsCalled : false,
500 initEvents: function()
503 if (this._initEventsCalled) { // as we call render... prevent looping...
506 this._initEventsCalled = true;
509 throw "can not find store for combo";
512 this.store = Roo.factory(this.store, Roo.data);
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) {
519 // remove this element....
520 var e = this.el.dom, k=0;
521 while (e ) { e = e.previousSibling; ++k;}
526 this.rendered = false;
528 this.render(this.parent().getChildContainer(true), k);
539 if(Roo.isTouch && this.mobileTouchView){
540 this.initTouchView();
545 this.initTickableEvents();
549 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
553 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
555 this.hiddenField.dom.value =
556 this.hiddenValue !== undefined ? this.hiddenValue :
557 this.value !== undefined ? this.value : '';
559 // prevent input submission
560 this.el.dom.removeAttribute('name');
561 this.hiddenField.dom.setAttribute('name', this.hiddenName);
566 // this.el.dom.setAttribute('autocomplete', 'off');
569 var cls = 'x-combo-list';
571 //this.list = new Roo.Layer({
572 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
578 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
579 _this.list.setWidth(lw);
582 this.list.on('mouseover', this.onViewOver, this);
583 this.list.on('mousemove', this.onViewMove, this);
585 this.list.on('scroll', this.onViewScroll, this);
588 this.list.swallowEvent('mousewheel');
589 this.assetHeight = 0;
592 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
593 this.assetHeight += this.header.getHeight();
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'));
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);
607 this.footer = this.list.createChild({cls:cls+'-ft'});
608 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
609 {pageSize: this.pageSize});
613 if (this.pageTb && this.allowBlank && !this.disableClear) {
615 this.pageTb.add(new Roo.Toolbar.Fill(), {
616 cls: 'x-btn-icon x-btn-clear',
622 _this.onSelect(false, -1);
627 this.assetHeight += this.footer.getHeight();
632 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
635 this.view = new Roo.View(this.list, this.tpl, {
636 singleSelect:true, store: this.store, selectedClass: this.selectedClass
638 //this.view.wrapEl.setDisplayed(false);
639 this.view.on('click', this.onViewClick, this);
643 this.store.on('beforeload', this.onBeforeLoad, this);
644 this.store.on('load', this.onLoad, this);
645 this.store.on('loadexception', this.onLoadException, this);
648 this.resizer = new Roo.Resizable(this.list, {
649 pinned:true, handles:'se'
651 this.resizer.on('resize', function(r, w, h){
652 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
654 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
655 this.restrictHeight();
657 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
661 this.editable = true;
662 this.setEditable(false);
667 if (typeof(this.events.add.listeners) != 'undefined') {
669 this.addicon = this.wrap.createChild(
670 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
672 this.addicon.on('click', function(e) {
673 this.fireEvent('add', this);
676 if (typeof(this.events.edit.listeners) != 'undefined') {
678 this.editicon = this.wrap.createChild(
679 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
681 this.editicon.setStyle('margin-left', '40px');
683 this.editicon.on('click', function(e) {
685 // we fire even if inothing is selected..
686 this.fireEvent('edit', this, this.lastData );
692 this.keyNav = new Roo.KeyNav(this.inputEl(), {
694 this.inKeyMode = true;
698 "down" : function(e){
699 if(!this.isExpanded()){
700 this.onTriggerClick();
702 this.inKeyMode = true;
707 "enter" : function(e){
708 // this.onViewClick();
712 if(this.fireEvent("specialkey", this, e)){
713 this.onViewClick(false);
726 if(this.fireEvent("specialkey", this, e)){
727 this.onViewClick(false);
735 doRelay : function(foo, bar, hname){
736 if(hname == 'down' || this.scope.isExpanded()){
737 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
746 this.queryDelay = Math.max(this.queryDelay || 10,
747 this.mode == 'local' ? 10 : 250);
750 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
753 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
755 if(this.editable !== false){
756 this.inputEl().on("keyup", this.onKeyUp, this);
758 if(this.forceSelection){
759 this.inputEl().on('blur', this.doForce, this);
763 this.choices = this.el.select('ul.select2-choices', true).first();
764 this.searchField = this.el.select('ul li.select2-search-field', true).first();
768 initTickableEvents: function()
774 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
776 this.hiddenField.dom.value =
777 this.hiddenValue !== undefined ? this.hiddenValue :
778 this.value !== undefined ? this.value : '';
780 // prevent input submission
781 this.el.dom.removeAttribute('name');
782 this.hiddenField.dom.setAttribute('name', this.hiddenName);
787 // this.list = this.el.select('ul.dropdown-menu',true).first();
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});
795 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
796 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
798 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
799 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
801 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
802 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
804 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
805 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
806 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
809 this.cancelBtn.hide();
814 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
815 _this.list.setWidth(lw);
818 this.list.on('mouseover', this.onViewOver, this);
819 this.list.on('mousemove', this.onViewMove, this);
821 this.list.on('scroll', this.onViewScroll, this);
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>';
827 this.view = new Roo.View(this.list, this.tpl, {
828 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
831 //this.view.wrapEl.setDisplayed(false);
832 this.view.on('click', this.onViewClick, this);
836 this.store.on('beforeload', this.onBeforeLoad, this);
837 this.store.on('load', this.onLoad, this);
838 this.store.on('loadexception', this.onLoadException, this);
841 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
843 this.inKeyMode = true;
847 "down" : function(e){
848 this.inKeyMode = true;
852 "enter" : function(e){
853 if(this.fireEvent("specialkey", this, e)){
854 this.onViewClick(false);
861 this.onTickableFooterButtonClick(e, false, false);
865 this.fireEvent("specialkey", this, e);
867 this.onTickableFooterButtonClick(e, false, false);
874 doRelay : function(e, fn, key){
875 if(this.scope.isExpanded()){
876 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
885 this.queryDelay = Math.max(this.queryDelay || 10,
886 this.mode == 'local' ? 10 : 250);
889 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
892 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
895 if(this.editable !== false){
896 this.tickableInputEl().on("keyup", this.onKeyUp, this);
901 onDestroy : function(){
903 this.view.setStore(null);
904 this.view.el.removeAllListeners();
905 this.view.el.remove();
906 this.view.purgeListeners();
909 this.list.dom.innerHTML = '';
913 this.store.un('beforeload', this.onBeforeLoad, this);
914 this.store.un('load', this.onLoad, this);
915 this.store.un('loadexception', this.onLoadException, this);
917 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
921 fireKey : function(e){
922 if(e.isNavKeyPress() && !this.list.isVisible()){
923 this.fireEvent("specialkey", this, e);
928 onResize: function(w, h){
929 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
931 // if(typeof w != 'number'){
932 // // we do not handle it!?!?
935 // var tw = this.trigger.getWidth();
936 // // tw += this.addicon ? this.addicon.getWidth() : 0;
937 // // tw += this.editicon ? this.editicon.getWidth() : 0;
939 // this.inputEl().setWidth( this.adjustWidth('input', x));
941 // //this.trigger.setStyle('left', x+'px');
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'));
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
959 setEditable : function(value){
960 if(value == this.editable){
963 this.editable = value;
965 this.inputEl().dom.setAttribute('readOnly', true);
966 this.inputEl().on('mousedown', this.onTriggerClick, this);
967 this.inputEl().addClass('x-combo-noedit');
969 this.inputEl().dom.setAttribute('readOnly', false);
970 this.inputEl().un('mousedown', this.onTriggerClick, this);
971 this.inputEl().removeClass('x-combo-noedit');
977 onBeforeLoad : function(combo,opts){
982 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
984 this.restrictHeight();
985 this.selectedIndex = -1;
991 this.hasQuery = false;
997 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1001 if(this.store.getCount() > 0){
1003 this.restrictHeight();
1004 if(this.lastQuery == this.allQuery){
1005 if(this.editable && !this.tickable){
1006 this.inputEl().dom.select();
1010 !this.selectByValue(this.value, true) &&
1013 !this.store.lastOptions ||
1014 typeof(this.store.lastOptions.add) == 'undefined' ||
1015 this.store.lastOptions.add != true
1018 this.select(0, true);
1024 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1025 this.taTask.delay(this.typeAheadDelay);
1029 this.onEmptyResults();
1035 onLoadException : function()
1037 this.hasQuery = false;
1039 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1040 this.loading.hide();
1043 if(this.tickable && this.editable){
1048 // only causes errors at present
1049 //Roo.log(this.store.reader.jsonData);
1050 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1052 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
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;
1065 if(selStart != len){
1066 this.setRawValue(newValue);
1067 this.selectText(selStart, newValue.length);
1073 onSelect : function(record, index){
1075 if(this.fireEvent('beforeselect', this, record, index) !== false){
1077 this.setFromData(index > -1 ? record.data : false);
1080 this.fireEvent('select', this, record, index);
1085 * Returns the currently selected field value or empty string if no value is set.
1086 * @return {String} value The selected value
1088 getValue : function(){
1091 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1094 if(this.valueField){
1095 return typeof this.value != 'undefined' ? this.value : '';
1097 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1102 * Clears any text/value currently set in the field
1104 clearValue : function(){
1105 if(this.hiddenField){
1106 this.hiddenField.dom.value = '';
1109 this.setRawValue('');
1110 this.lastSelectionText = '';
1111 this.lastData = false;
1113 var close = this.closeTriggerEl();
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
1128 setValue : function(v){
1135 if(this.valueField){
1136 var r = this.findRecord(this.valueField, v);
1138 text = r.data[this.displayField];
1139 }else if(this.valueNotFoundText !== undefined){
1140 text = this.valueNotFoundText;
1143 this.lastSelectionText = text;
1144 if(this.hiddenField){
1145 this.hiddenField.dom.value = v;
1147 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1150 var close = this.closeTriggerEl();
1153 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1157 * @property {Object} the last set data for the element
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?
1165 setFromData : function(o){
1172 var dv = ''; // display value
1173 var vv = ''; // value value..
1175 if (this.displayField) {
1176 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1178 // this is an error condition!!!
1179 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1182 if(this.valueField){
1183 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1186 var close = this.closeTriggerEl();
1189 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1192 if(this.hiddenField){
1193 this.hiddenField.dom.value = vv;
1195 this.lastSelectionText = dv;
1196 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
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);
1211 // overridden so that last data is reset..
1218 this.setValue(this.originalValue);
1219 this.clearInvalid();
1220 this.lastData = false;
1222 this.view.clearSelections();
1226 findRecord : function(prop, value){
1228 if(this.store.getCount() > 0){
1229 this.store.each(function(r){
1230 if(r.data[prop] == value){
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 || '');
1248 onViewMove : function(e, t){
1249 this.inKeyMode = false;
1253 onViewOver : function(e, t){
1254 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1257 var item = this.view.findItemFromChild(t);
1260 var index = this.view.indexOf(item);
1261 this.select(index, false);
1266 onViewClick : function(view, doFocus, el, e)
1268 var index = this.view.getSelectedIndexes()[0];
1270 var r = this.store.getAt(index);
1274 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1283 Roo.each(this.tickItems, function(v,k){
1285 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1287 _this.tickItems.splice(k, 1);
1289 if(typeof(e) == 'undefined' && view == false){
1290 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1297 Roo.log(this.tickItems);
1302 Roo.log(this.tickItems);
1303 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1304 //this.tickItems.push(r.data);
1306 Roo.log(this.tickItems);
1307 if(typeof(e) == 'undefined' && view == false){
1308 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1315 this.onSelect(r, index);
1317 if(doFocus !== false && !this.blockFocus){
1318 this.inputEl().focus();
1323 restrictHeight : function(){
1324 //this.innerList.dom.style.height = '';
1325 //var inner = this.innerList.dom;
1326 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1327 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1328 //this.list.beginUpdate();
1329 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1330 this.list.alignTo(this.inputEl(), this.listAlign);
1331 this.list.alignTo(this.inputEl(), this.listAlign);
1332 //this.list.endUpdate();
1336 onEmptyResults : function(){
1338 if(this.tickable && this.editable){
1339 this.restrictHeight();
1347 * Returns true if the dropdown list is expanded, else false.
1349 isExpanded : function(){
1350 return this.list.isVisible();
1354 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1355 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1356 * @param {String} value The data value of the item to select
1357 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1358 * selected item if it is not currently in view (defaults to true)
1359 * @return {Boolean} True if the value matched an item in the list, else false
1361 selectByValue : function(v, scrollIntoView){
1362 if(v !== undefined && v !== null){
1363 var r = this.findRecord(this.valueField || this.displayField, v);
1365 this.select(this.store.indexOf(r), scrollIntoView);
1373 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1374 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1375 * @param {Number} index The zero-based index of the list item to select
1376 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1377 * selected item if it is not currently in view (defaults to true)
1379 select : function(index, scrollIntoView){
1380 this.selectedIndex = index;
1381 this.view.select(index);
1382 if(scrollIntoView !== false){
1383 var el = this.view.getNode(index);
1385 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1388 this.list.scrollChildIntoView(el, false);
1394 selectNext : function(){
1395 var ct = this.store.getCount();
1397 if(this.selectedIndex == -1){
1399 }else if(this.selectedIndex < ct-1){
1400 this.select(this.selectedIndex+1);
1406 selectPrev : function(){
1407 var ct = this.store.getCount();
1409 if(this.selectedIndex == -1){
1411 }else if(this.selectedIndex != 0){
1412 this.select(this.selectedIndex-1);
1418 onKeyUp : function(e){
1419 if(this.editable !== false && !e.isSpecialKey()){
1420 this.lastKey = e.getKey();
1421 this.dqTask.delay(this.queryDelay);
1426 validateBlur : function(){
1427 return !this.list || !this.list.isVisible();
1431 initQuery : function(){
1433 var v = this.getRawValue();
1435 if(this.tickable && this.editable){
1436 v = this.tickableInputEl().getValue();
1443 doForce : function(){
1444 if(this.inputEl().dom.value.length > 0){
1445 this.inputEl().dom.value =
1446 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1452 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1453 * query allowing the query action to be canceled if needed.
1454 * @param {String} query The SQL query to execute
1455 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1456 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1457 * saved in the current store (defaults to false)
1459 doQuery : function(q, forceAll){
1461 if(q === undefined || q === null){
1470 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1475 forceAll = qe.forceAll;
1476 if(forceAll === true || (q.length >= this.minChars)){
1478 this.hasQuery = true;
1480 if(this.lastQuery != q || this.alwaysQuery){
1482 if(this.mode == 'local'){
1483 this.selectedIndex = -1;
1485 this.store.clearFilter();
1488 if(this.specialFilter){
1489 this.fireEvent('specialfilter', this);
1494 this.store.filter(this.displayField, q);
1497 this.store.fireEvent("datachanged", this.store);
1504 this.store.baseParams[this.queryParam] = q;
1506 var options = {params : this.getParams(q)};
1510 options.params.start = this.page * this.pageSize;
1513 this.store.load(options);
1516 * this code will make the page width larger, at the beginning, the list not align correctly,
1517 * we should expand the list on onLoad
1523 this.selectedIndex = -1;
1528 this.loadNext = false;
1532 getParams : function(q){
1534 //p[this.queryParam] = q;
1538 p.limit = this.pageSize;
1544 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1546 collapse : function(){
1547 if(!this.isExpanded()){
1554 this.hasFocus = false;
1556 this.cancelBtn.hide();
1557 this.trigger.show();
1560 this.tickableInputEl().dom.value = '';
1561 this.tickableInputEl().blur();
1566 Roo.get(document).un('mousedown', this.collapseIf, this);
1567 Roo.get(document).un('mousewheel', this.collapseIf, this);
1568 if (!this.editable) {
1569 Roo.get(document).un('keydown', this.listKeyPress, this);
1571 this.fireEvent('collapse', this);
1575 collapseIf : function(e){
1576 var in_combo = e.within(this.el);
1577 var in_list = e.within(this.list);
1578 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1580 if (in_combo || in_list || is_list) {
1581 //e.stopPropagation();
1586 this.onTickableFooterButtonClick(e, false, false);
1594 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1596 expand : function(){
1598 if(this.isExpanded() || !this.hasFocus){
1602 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1603 this.list.setWidth(lw);
1610 this.restrictHeight();
1614 this.tickItems = Roo.apply([], this.item);
1617 this.cancelBtn.show();
1618 this.trigger.hide();
1621 this.tickableInputEl().focus();
1626 Roo.get(document).on('mousedown', this.collapseIf, this);
1627 Roo.get(document).on('mousewheel', this.collapseIf, this);
1628 if (!this.editable) {
1629 Roo.get(document).on('keydown', this.listKeyPress, this);
1632 this.fireEvent('expand', this);
1636 // Implements the default empty TriggerField.onTriggerClick function
1637 onTriggerClick : function(e)
1639 Roo.log('trigger click');
1641 if(this.disabled || !this.triggerList){
1646 this.loadNext = false;
1648 if(this.isExpanded()){
1650 if (!this.blockFocus) {
1651 this.inputEl().focus();
1655 this.hasFocus = true;
1656 if(this.triggerAction == 'all') {
1657 this.doQuery(this.allQuery, true);
1659 this.doQuery(this.getRawValue());
1661 if (!this.blockFocus) {
1662 this.inputEl().focus();
1667 onTickableTriggerClick : function(e)
1674 this.loadNext = false;
1675 this.hasFocus = true;
1677 if(this.triggerAction == 'all') {
1678 this.doQuery(this.allQuery, true);
1680 this.doQuery(this.getRawValue());
1684 onSearchFieldClick : function(e)
1686 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1687 this.onTickableFooterButtonClick(e, false, false);
1691 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1696 this.loadNext = false;
1697 this.hasFocus = true;
1699 if(this.triggerAction == 'all') {
1700 this.doQuery(this.allQuery, true);
1702 this.doQuery(this.getRawValue());
1706 listKeyPress : function(e)
1708 //Roo.log('listkeypress');
1709 // scroll to first matching element based on key pres..
1710 if (e.isSpecialKey()) {
1713 var k = String.fromCharCode(e.getKey()).toUpperCase();
1716 var csel = this.view.getSelectedNodes();
1717 var cselitem = false;
1719 var ix = this.view.indexOf(csel[0]);
1720 cselitem = this.store.getAt(ix);
1721 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1727 this.store.each(function(v) {
1729 // start at existing selection.
1730 if (cselitem.id == v.id) {
1736 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1737 match = this.store.indexOf(v);
1743 if (match === false) {
1744 return true; // no more action?
1747 this.view.select(match);
1748 var sn = Roo.get(this.view.getSelectedNodes()[0])
1749 sn.scrollIntoView(sn.dom.parentNode, false);
1752 onViewScroll : function(e, t){
1754 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){
1758 this.hasQuery = true;
1760 this.loading = this.list.select('.loading', true).first();
1762 if(this.loading === null){
1763 this.list.createChild({
1765 cls: 'loading select2-more-results select2-active',
1766 html: 'Loading more results...'
1769 this.loading = this.list.select('.loading', true).first();
1771 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1773 this.loading.hide();
1776 this.loading.show();
1781 this.loadNext = true;
1783 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1788 addItem : function(o)
1790 var dv = ''; // display value
1792 if (this.displayField) {
1793 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1795 // this is an error condition!!!
1796 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1803 var choice = this.choices.createChild({
1805 cls: 'select2-search-choice',
1814 cls: 'select2-search-choice-close',
1819 }, this.searchField);
1821 var close = choice.select('a.select2-search-choice-close', true).first()
1823 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1831 this.inputEl().dom.value = '';
1836 onRemoveItem : function(e, _self, o)
1840 this.lastItem = Roo.apply([], this.item);
1842 var index = this.item.indexOf(o.data) * 1;
1845 Roo.log('not this item?!');
1849 this.item.splice(index, 1);
1854 this.fireEvent('remove', this, e);
1860 syncValue : function()
1862 if(!this.item.length){
1869 Roo.each(this.item, function(i){
1870 if(_this.valueField){
1871 value.push(i[_this.valueField]);
1878 this.value = value.join(',');
1880 if(this.hiddenField){
1881 this.hiddenField.dom.value = this.value;
1884 this.store.fireEvent("datachanged", this.store);
1887 clearItem : function()
1895 Roo.each(this.choices.select('>li.select2-search-choice', true).elements, function(c){
1903 if(this.tickable && !Roo.isTouch){
1904 this.view.refresh();
1908 inputEl: function ()
1910 if(Roo.isTouch && this.mobileTouchView){
1911 return this.el.select('input.form-control',true).first();
1915 return this.searchField;
1918 return this.el.select('input.form-control',true).first();
1922 onTickableFooterButtonClick : function(e, btn, el)
1926 this.lastItem = Roo.apply([], this.item);
1928 if(btn && btn.name == 'cancel'){
1929 this.tickItems = Roo.apply([], this.item);
1938 Roo.each(this.tickItems, function(o){
1946 validate : function()
1948 var v = this.getRawValue();
1951 v = this.getValue();
1954 if(this.disabled || this.allowBlank || v.length){
1963 tickableInputEl : function()
1965 if(!this.tickable || !this.editable){
1966 return this.inputEl();
1969 return this.inputEl().select('.select2-search-field-input', true).first();
1973 getAutoCreateTouchView : function()
1978 cls: 'form-group' //input-group
1984 type : this.inputType,
1985 cls : 'form-control x-combo-noedit',
1986 autocomplete: 'new-password',
1987 placeholder : this.placeholder || '',
1992 input.name = this.name;
1996 input.cls += ' input-' + this.size;
1999 if (this.disabled) {
2000 input.disabled = true;
2011 inputblock.cls += ' input-group';
2013 inputblock.cn.unshift({
2015 cls : 'input-group-addon',
2020 if(this.removable && !this.multiple){
2021 inputblock.cls += ' roo-removable';
2023 inputblock.cn.push({
2026 cls : 'roo-combo-removable-btn close'
2030 if(this.hasFeedback && !this.allowBlank){
2032 inputblock.cls += ' has-feedback';
2034 inputblock.cn.push({
2036 cls: 'glyphicon form-control-feedback'
2043 inputblock.cls += (this.before) ? '' : ' input-group';
2045 inputblock.cn.push({
2047 cls : 'input-group-addon',
2058 cls: 'form-hidden-field'
2072 cls: 'form-hidden-field'
2076 cls: 'select2-choices',
2080 cls: 'select2-search-field',
2093 cls: 'select2-container input-group',
2100 combobox.cls += ' select2-container-multi';
2103 var align = this.labelAlign || this.parentLabelAlign();
2107 if(this.fieldLabel.length){
2109 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2110 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2115 cls : 'control-label ' + lw,
2116 html : this.fieldLabel
2128 var settings = this;
2130 ['xs','sm','md','lg'].map(function(size){
2131 if (settings[size]) {
2132 cfg.cls += ' col-' + size + '-' + settings[size];
2139 initTouchView : function()
2141 this.renderTouchView();
2143 this.touchViewEl.on('scroll', function(){
2144 this.el.dom.scrollTop = 0;
2147 this.inputEl().on("click", this.showTouchView, this);
2148 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2149 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2151 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2153 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2154 this.store.on('load', this.onTouchViewLoad, this);
2155 this.store.on('loadexception', this.onTouchViewLoadException, this);
2157 if(this.hiddenName){
2159 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2161 this.hiddenField.dom.value =
2162 this.hiddenValue !== undefined ? this.hiddenValue :
2163 this.value !== undefined ? this.value : '';
2165 this.el.dom.removeAttribute('name');
2166 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2170 this.choices = this.el.select('ul.select2-choices', true).first();
2171 this.searchField = this.el.select('ul li.select2-search-field', true).first();
2174 if(this.removable && !this.multiple){
2175 var close = this.closeTriggerEl();
2177 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2178 close.on('click', this.removeBtnClick, this, close);
2187 renderTouchView : function()
2189 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2190 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2192 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2193 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2195 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2196 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2197 this.touchViewBodyEl.setStyle('overflow', 'auto');
2199 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2200 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2202 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2203 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2207 showTouchView : function()
2209 this.touchViewHeaderEl.hide();
2211 if(this.fieldLabel.length){
2212 this.touchViewHeaderEl.dom.innerHTML = this.fieldLabel;
2213 this.touchViewHeaderEl.show();
2216 this.touchViewEl.show();
2218 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2219 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2221 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2223 if(this.fieldLabel.length){
2224 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2227 this.touchViewBodyEl.setHeight(bodyHeight);
2231 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2233 this.touchViewEl.addClass('in');
2236 this.doTouchViewQuery();
2240 hideTouchView : function()
2242 this.touchViewEl.removeClass('in');
2246 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2248 this.touchViewEl.setStyle('display', 'none');
2253 setTouchViewValue : function()
2260 Roo.each(this.tickItems, function(o){
2265 this.hideTouchView();
2268 doTouchViewQuery : function()
2277 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2281 if(!this.alwaysQuery || this.mode == 'local'){
2282 this.onTouchViewLoad();
2289 onTouchViewBeforeLoad : function(combo,opts)
2295 onTouchViewLoad : function()
2297 if(this.store.getCount() < 1){
2298 this.onTouchViewEmptyResults();
2302 this.clearTouchView();
2304 var rawValue = this.getRawValue();
2306 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2308 this.tickItems = [];
2310 this.store.data.each(function(d, rowIndex){
2311 var row = this.touchViewListGroup.createChild(template);
2313 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2314 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = d.data[this.displayField];
2317 if(!this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue()){
2318 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2321 if(this.multiple && this.valueField && typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1){
2322 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2323 this.tickItems.push(d.data);
2326 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2330 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2332 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2334 if(this.fieldLabel.length){
2335 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2338 var listHeight = this.touchViewListGroup.getHeight();
2342 if(firstChecked && listHeight > bodyHeight){
2343 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2348 onTouchViewLoadException : function()
2350 this.hideTouchView();
2353 onTouchViewEmptyResults : function()
2355 this.clearTouchView();
2357 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2359 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2363 clearTouchView : function()
2365 this.touchViewListGroup.dom.innerHTML = '';
2368 onTouchViewClick : function(e, el, o)
2373 var rowIndex = o.rowIndex;
2375 var r = this.store.getAt(rowIndex);
2378 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2379 c.dom.removeAttribute('checked');
2382 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2384 this.setFromData(r.data);
2386 var close = this.closeTriggerEl();
2392 this.hideTouchView();
2394 this.fireEvent('select', this, r, rowIndex);
2399 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2400 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2401 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2405 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2406 this.addItem(r.data);
2407 this.tickItems.push(r.data);
2413 * @cfg {Boolean} grow
2417 * @cfg {Number} growMin
2421 * @cfg {Number} growMax
2430 Roo.apply(Roo.bootstrap.ComboBox, {
2434 cls: 'modal-header',
2456 cls: 'list-group-item',
2460 cls: 'roo-combobox-list-group-item-value'
2464 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2478 listItemCheckbox : {
2480 cls: 'list-group-item',
2484 cls: 'roo-combobox-list-group-item-value'
2488 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2504 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2509 cls: 'modal-footer',
2517 cls: 'col-xs-6 text-left',
2520 cls: 'btn btn-danger roo-touch-view-cancel',
2526 cls: 'col-xs-6 text-right',
2529 cls: 'btn btn-success roo-touch-view-ok',
2540 Roo.apply(Roo.bootstrap.ComboBox, {
2542 touchViewTemplate : {
2544 cls: 'modal fade roo-combobox-touch-view',
2548 cls: 'modal-dialog',
2552 cls: 'modal-content',
2554 Roo.bootstrap.ComboBox.header,
2555 Roo.bootstrap.ComboBox.body,
2556 Roo.bootstrap.ComboBox.footer