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
86 * Fires when the remove value from the combobox array
87 * @param {Roo.bootstrap.ComboBox} combo This combo box
91 * @event specialfilter
92 * Fires when specialfilter
93 * @param {Roo.bootstrap.ComboBox} combo This combo box
95 'specialfilter' : true,
98 * Fires when tick the element
99 * @param {Roo.bootstrap.ComboBox} combo This combo box
103 * @event touchviewdisplay
104 * Fires when touch view require special display (default is using displayField)
105 * @param {Roo.bootstrap.ComboBox} combo This combo box
106 * @param {Object} cfg set html .
108 'touchviewdisplay' : true
115 this.selectedIndex = -1;
116 if(this.mode == 'local'){
117 if(config.queryDelay === undefined){
118 this.queryDelay = 10;
120 if(config.minChars === undefined){
126 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
129 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
130 * rendering into an Roo.Editor, defaults to false)
133 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
134 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
137 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
140 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
141 * the dropdown list (defaults to undefined, with no header element)
145 * @cfg {String/Roo.Template} tpl The template to use to render the output
149 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
151 listWidth: undefined,
153 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
154 * mode = 'remote' or 'text' if mode = 'local')
156 displayField: undefined,
159 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
160 * mode = 'remote' or 'value' if mode = 'local').
161 * Note: use of a valueField requires the user make a selection
162 * in order for a value to be mapped.
164 valueField: undefined,
166 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
171 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
172 * field's data value (defaults to the underlying DOM element's name)
174 hiddenName: undefined,
176 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
180 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
182 selectedClass: 'active',
185 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
189 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
190 * anchor positions (defaults to 'tl-bl')
194 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
198 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
199 * query specified by the allQuery config option (defaults to 'query')
201 triggerAction: 'query',
203 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
204 * (defaults to 4, does not apply if editable = false)
208 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
209 * delay (typeAheadDelay) if it matches a known value (defaults to false)
213 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
214 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
218 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
219 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
223 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
224 * when editable = true (defaults to false)
228 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
232 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
233 * when mode = 'remote' (defaults to 'Loading...')
235 loadingText: 'Loading...',
237 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
241 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
245 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
246 * traditional select (defaults to true)
250 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
254 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
258 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
259 * listWidth has a higher value)
263 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
264 * allow the user to set arbitrary text into the field (defaults to false)
266 forceSelection:false,
268 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
269 * if typeAhead = true (defaults to 250)
271 typeAheadDelay : 250,
273 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
274 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
276 valueNotFoundText : undefined,
278 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
283 * @cfg {Boolean} disableClear Disable showing of clear button.
285 disableClear : false,
287 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
292 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
297 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
299 invalidClass : "has-warning",
302 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
304 validClass : "has-success",
307 * @cfg {Boolean} specialFilter (true|false) special filter default false
309 specialFilter : false,
312 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
314 mobileTouchView : true,
317 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
319 useNativeIOS : false,
333 btnPosition : 'right',
335 showToggleBtn : true,
337 emptyResultText: 'Empty',
338 triggerText : 'Select',
340 // element that contains real text value.. (when hidden is used..)
342 getAutoCreate : function()
347 * Render classic select for iso
350 if(Roo.isIOS && this.useNativeIOS){
351 cfg = this.getAutoCreateNativeIOS();
359 if(Roo.isTouch && this.mobileTouchView){
360 cfg = this.getAutoCreateTouchView();
368 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
369 if(this.name == 'info_year_invest_id_display_name'){
370 Roo.log('cfg.................................................');
377 * ComboBox with tickable selections
380 var align = this.labelAlign || this.parentLabelAlign();
383 cls : 'form-group roo-combobox-tickable' //input-group
386 var btn_text_select = '';
387 var btn_text_done = '';
388 var btn_text_cancel = '';
390 if (this.btn_text_show) {
391 btn_text_select = 'Select';
392 btn_text_done = 'Done';
393 btn_text_cancel = 'Cancel';
398 cls : 'tickable-buttons',
403 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
404 //html : this.triggerText
405 html: btn_text_select
411 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
419 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
421 html: btn_text_cancel
429 cls: 'roo-select2-search-field-input'
435 Roo.each(buttons.cn, function(c){
437 c.cls += ' btn-' + _this.size;
440 if (_this.disabled) {
451 cls: 'form-hidden-field'
455 cls: 'roo-select2-choices',
459 cls: 'roo-select2-search-field',
470 cls: 'roo-select2-container input-group roo-select2-container-multi',
475 // cls: 'typeahead typeahead-long dropdown-menu',
476 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
481 if(this.hasFeedback && !this.allowBlank){
485 cls: 'glyphicon form-control-feedback'
488 combobox.cn.push(feedback);
492 if (align ==='left' && this.fieldLabel.length) {
494 cfg.cls += ' roo-form-group-label-left';
499 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
500 tooltip : 'This field is required'
505 cls : 'control-label',
506 html : this.fieldLabel
518 var labelCfg = cfg.cn[1];
519 var contentCfg = cfg.cn[2];
522 if(this.indicatorpos == 'right'){
528 cls : 'control-label',
529 html : this.fieldLabel
533 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
534 tooltip : 'This field is required'
548 labelCfg = cfg.cn[0];
549 contentCfg = cfg.cn[2];
553 if(this.labelWidth > 12){
554 labelCfg.style = "width: " + this.labelWidth + 'px';
557 if(this.labelWidth < 13 && this.labelmd == 0){
558 this.labelmd = this.labelWidth;
561 if(this.labellg > 0){
562 labelCfg.cls += ' col-lg-' + this.labellg;
563 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
566 if(this.labelmd > 0){
567 labelCfg.cls += ' col-md-' + this.labelmd;
568 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
571 if(this.labelsm > 0){
572 labelCfg.cls += ' col-sm-' + this.labelsm;
573 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
576 if(this.labelxs > 0){
577 labelCfg.cls += ' col-xs-' + this.labelxs;
578 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
582 } else if ( this.fieldLabel.length) {
583 // Roo.log(" label");
587 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
588 tooltip : 'This field is required'
592 //cls : 'input-group-addon',
593 html : this.fieldLabel
601 if(this.indicatorpos == 'right'){
606 //cls : 'input-group-addon',
607 html : this.fieldLabel
613 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
614 tooltip : 'This field is required'
625 // Roo.log(" no label && no align");
632 ['xs','sm','md','lg'].map(function(size){
633 if (settings[size]) {
634 cfg.cls += ' col-' + size + '-' + settings[size];
642 _initEventsCalled : false,
645 initEvents: function()
647 if (this._initEventsCalled) { // as we call render... prevent looping...
650 this._initEventsCalled = true;
653 throw "can not find store for combo";
656 this.store = Roo.factory(this.store, Roo.data);
658 // if we are building from html. then this element is so complex, that we can not really
659 // use the rendered HTML.
660 // so we have to trash and replace the previous code.
661 if (Roo.XComponent.build_from_html) {
663 // remove this element....
664 var e = this.el.dom, k=0;
665 while (e ) { e = e.previousSibling; ++k;}
670 this.rendered = false;
672 this.render(this.parent().getChildContainer(true), k);
678 if(Roo.isIOS && this.useNativeIOS){
687 if(Roo.isTouch && this.mobileTouchView){
688 this.initTouchView();
693 this.initTickableEvents();
697 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
701 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
703 this.hiddenField.dom.value =
704 this.hiddenValue !== undefined ? this.hiddenValue :
705 this.value !== undefined ? this.value : '';
707 // prevent input submission
708 this.el.dom.removeAttribute('name');
709 this.hiddenField.dom.setAttribute('name', this.hiddenName);
714 // this.el.dom.setAttribute('autocomplete', 'off');
717 var cls = 'x-combo-list';
719 //this.list = new Roo.Layer({
720 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
726 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
727 _this.list.setWidth(lw);
730 this.list.on('mouseover', this.onViewOver, this);
731 this.list.on('mousemove', this.onViewMove, this);
733 this.list.on('scroll', this.onViewScroll, this);
736 this.list.swallowEvent('mousewheel');
737 this.assetHeight = 0;
740 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
741 this.assetHeight += this.header.getHeight();
744 this.innerList = this.list.createChild({cls:cls+'-inner'});
745 this.innerList.on('mouseover', this.onViewOver, this);
746 this.innerList.on('mousemove', this.onViewMove, this);
747 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
749 if(this.allowBlank && !this.pageSize && !this.disableClear){
750 this.footer = this.list.createChild({cls:cls+'-ft'});
751 this.pageTb = new Roo.Toolbar(this.footer);
755 this.footer = this.list.createChild({cls:cls+'-ft'});
756 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
757 {pageSize: this.pageSize});
761 if (this.pageTb && this.allowBlank && !this.disableClear) {
763 this.pageTb.add(new Roo.Toolbar.Fill(), {
764 cls: 'x-btn-icon x-btn-clear',
770 _this.onSelect(false, -1);
775 this.assetHeight += this.footer.getHeight();
780 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
783 this.view = new Roo.View(this.list, this.tpl, {
784 singleSelect:true, store: this.store, selectedClass: this.selectedClass
786 //this.view.wrapEl.setDisplayed(false);
787 this.view.on('click', this.onViewClick, this);
791 this.store.on('beforeload', this.onBeforeLoad, this);
792 this.store.on('load', this.onLoad, this);
793 this.store.on('loadexception', this.onLoadException, this);
796 this.resizer = new Roo.Resizable(this.list, {
797 pinned:true, handles:'se'
799 this.resizer.on('resize', function(r, w, h){
800 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
802 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
803 this.restrictHeight();
805 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
809 this.editable = true;
810 this.setEditable(false);
815 if (typeof(this.events.add.listeners) != 'undefined') {
817 this.addicon = this.wrap.createChild(
818 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
820 this.addicon.on('click', function(e) {
821 this.fireEvent('add', this);
824 if (typeof(this.events.edit.listeners) != 'undefined') {
826 this.editicon = this.wrap.createChild(
827 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
829 this.editicon.setStyle('margin-left', '40px');
831 this.editicon.on('click', function(e) {
833 // we fire even if inothing is selected..
834 this.fireEvent('edit', this, this.lastData );
840 this.keyNav = new Roo.KeyNav(this.inputEl(), {
842 this.inKeyMode = true;
846 "down" : function(e){
847 if(!this.isExpanded()){
848 this.onTriggerClick();
850 this.inKeyMode = true;
855 "enter" : function(e){
856 // this.onViewClick();
860 if(this.fireEvent("specialkey", this, e)){
861 this.onViewClick(false);
874 if(this.fireEvent("specialkey", this, e)){
875 this.onViewClick(false);
883 doRelay : function(foo, bar, hname){
884 if(hname == 'down' || this.scope.isExpanded()){
885 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
894 this.queryDelay = Math.max(this.queryDelay || 10,
895 this.mode == 'local' ? 10 : 250);
898 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
901 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
903 if(this.editable !== false){
904 this.inputEl().on("keyup", this.onKeyUp, this);
906 if(this.forceSelection){
907 this.inputEl().on('blur', this.doForce, this);
911 this.choices = this.el.select('ul.roo-select2-choices', true).first();
912 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
916 initTickableEvents: function()
922 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
924 this.hiddenField.dom.value =
925 this.hiddenValue !== undefined ? this.hiddenValue :
926 this.value !== undefined ? this.value : '';
928 // prevent input submission
929 this.el.dom.removeAttribute('name');
930 this.hiddenField.dom.setAttribute('name', this.hiddenName);
935 // this.list = this.el.select('ul.dropdown-menu',true).first();
937 this.choices = this.el.select('ul.roo-select2-choices', true).first();
938 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
939 if(this.triggerList){
940 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
943 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
944 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
946 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
947 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
949 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
950 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
952 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
953 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
954 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
957 this.cancelBtn.hide();
962 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
963 _this.list.setWidth(lw);
966 this.list.on('mouseover', this.onViewOver, this);
967 this.list.on('mousemove', this.onViewMove, this);
969 this.list.on('scroll', this.onViewScroll, this);
972 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
975 this.view = new Roo.View(this.list, this.tpl, {
976 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
979 //this.view.wrapEl.setDisplayed(false);
980 this.view.on('click', this.onViewClick, this);
984 this.store.on('beforeload', this.onBeforeLoad, this);
985 this.store.on('load', this.onLoad, this);
986 this.store.on('loadexception', this.onLoadException, this);
989 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
991 this.inKeyMode = true;
995 "down" : function(e){
996 this.inKeyMode = true;
1000 "enter" : function(e){
1001 if(this.fireEvent("specialkey", this, e)){
1002 this.onViewClick(false);
1008 "esc" : function(e){
1009 this.onTickableFooterButtonClick(e, false, false);
1012 "tab" : function(e){
1013 this.fireEvent("specialkey", this, e);
1015 this.onTickableFooterButtonClick(e, false, false);
1022 doRelay : function(e, fn, key){
1023 if(this.scope.isExpanded()){
1024 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1033 this.queryDelay = Math.max(this.queryDelay || 10,
1034 this.mode == 'local' ? 10 : 250);
1037 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1040 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1043 if(this.editable !== false){
1044 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1047 this.indicator = this.indicatorEl();
1050 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1051 this.indicator.hide();
1056 onDestroy : function(){
1058 this.view.setStore(null);
1059 this.view.el.removeAllListeners();
1060 this.view.el.remove();
1061 this.view.purgeListeners();
1064 this.list.dom.innerHTML = '';
1068 this.store.un('beforeload', this.onBeforeLoad, this);
1069 this.store.un('load', this.onLoad, this);
1070 this.store.un('loadexception', this.onLoadException, this);
1072 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1076 fireKey : function(e){
1077 if(e.isNavKeyPress() && !this.list.isVisible()){
1078 this.fireEvent("specialkey", this, e);
1083 onResize: function(w, h){
1084 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1086 // if(typeof w != 'number'){
1087 // // we do not handle it!?!?
1090 // var tw = this.trigger.getWidth();
1091 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1092 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1094 // this.inputEl().setWidth( this.adjustWidth('input', x));
1096 // //this.trigger.setStyle('left', x+'px');
1098 // if(this.list && this.listWidth === undefined){
1099 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1100 // this.list.setWidth(lw);
1101 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1109 * Allow or prevent the user from directly editing the field text. If false is passed,
1110 * the user will only be able to select from the items defined in the dropdown list. This method
1111 * is the runtime equivalent of setting the 'editable' config option at config time.
1112 * @param {Boolean} value True to allow the user to directly edit the field text
1114 setEditable : function(value){
1115 if(value == this.editable){
1118 this.editable = value;
1120 this.inputEl().dom.setAttribute('readOnly', true);
1121 this.inputEl().on('mousedown', this.onTriggerClick, this);
1122 this.inputEl().addClass('x-combo-noedit');
1124 this.inputEl().dom.setAttribute('readOnly', false);
1125 this.inputEl().un('mousedown', this.onTriggerClick, this);
1126 this.inputEl().removeClass('x-combo-noedit');
1132 onBeforeLoad : function(combo,opts){
1137 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1139 this.restrictHeight();
1140 this.selectedIndex = -1;
1144 onLoad : function(){
1146 this.hasQuery = false;
1152 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1153 this.loading.hide();
1156 if(this.store.getCount() > 0){
1158 this.restrictHeight();
1159 if(this.lastQuery == this.allQuery){
1160 if(this.editable && !this.tickable){
1161 this.inputEl().dom.select();
1165 !this.selectByValue(this.value, true) &&
1168 !this.store.lastOptions ||
1169 typeof(this.store.lastOptions.add) == 'undefined' ||
1170 this.store.lastOptions.add != true
1173 this.select(0, true);
1179 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1180 this.taTask.delay(this.typeAheadDelay);
1184 this.onEmptyResults();
1190 onLoadException : function()
1192 this.hasQuery = false;
1194 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1195 this.loading.hide();
1198 if(this.tickable && this.editable){
1203 // only causes errors at present
1204 //Roo.log(this.store.reader.jsonData);
1205 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1207 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1213 onTypeAhead : function(){
1214 if(this.store.getCount() > 0){
1215 var r = this.store.getAt(0);
1216 var newValue = r.data[this.displayField];
1217 var len = newValue.length;
1218 var selStart = this.getRawValue().length;
1220 if(selStart != len){
1221 this.setRawValue(newValue);
1222 this.selectText(selStart, newValue.length);
1228 onSelect : function(record, index){
1230 if(this.fireEvent('beforeselect', this, record, index) !== false){
1232 this.setFromData(index > -1 ? record.data : false);
1235 this.fireEvent('select', this, record, index);
1240 * Returns the currently selected field value or empty string if no value is set.
1241 * @return {String} value The selected value
1243 getValue : function()
1245 if(Roo.isIOS && this.useNativeIOS){
1246 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1250 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1253 if(this.valueField){
1254 return typeof this.value != 'undefined' ? this.value : '';
1256 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1260 getRawValue : function()
1262 if(Roo.isIOS && this.useNativeIOS){
1263 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1266 var v = this.inputEl().getValue();
1272 * Clears any text/value currently set in the field
1274 clearValue : function(){
1276 if(this.hiddenField){
1277 this.hiddenField.dom.value = '';
1280 this.setRawValue('');
1281 this.lastSelectionText = '';
1282 this.lastData = false;
1284 var close = this.closeTriggerEl();
1295 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1296 * will be displayed in the field. If the value does not match the data value of an existing item,
1297 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1298 * Otherwise the field will be blank (although the value will still be set).
1299 * @param {String} value The value to match
1301 setValue : function(v)
1303 if(Roo.isIOS && this.useNativeIOS){
1304 this.setIOSValue(v);
1314 if(this.valueField){
1315 var r = this.findRecord(this.valueField, v);
1317 text = r.data[this.displayField];
1318 }else if(this.valueNotFoundText !== undefined){
1319 text = this.valueNotFoundText;
1322 this.lastSelectionText = text;
1323 if(this.hiddenField){
1324 this.hiddenField.dom.value = v;
1326 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1329 var close = this.closeTriggerEl();
1332 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1338 * @property {Object} the last set data for the element
1343 * Sets the value of the field based on a object which is related to the record format for the store.
1344 * @param {Object} value the value to set as. or false on reset?
1346 setFromData : function(o){
1353 var dv = ''; // display value
1354 var vv = ''; // value value..
1356 if (this.displayField) {
1357 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1359 // this is an error condition!!!
1360 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1363 if(this.valueField){
1364 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1367 var close = this.closeTriggerEl();
1370 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1373 if(this.hiddenField){
1374 this.hiddenField.dom.value = vv;
1376 this.lastSelectionText = dv;
1377 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1381 // no hidden field.. - we store the value in 'value', but still display
1382 // display field!!!!
1383 this.lastSelectionText = dv;
1384 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1392 // overridden so that last data is reset..
1399 this.setValue(this.originalValue);
1400 //this.clearInvalid();
1401 this.lastData = false;
1403 this.view.clearSelections();
1409 findRecord : function(prop, value){
1411 if(this.store.getCount() > 0){
1412 this.store.each(function(r){
1413 if(r.data[prop] == value){
1425 // returns hidden if it's set..
1426 if (!this.rendered) {return ''};
1427 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1431 onViewMove : function(e, t){
1432 this.inKeyMode = false;
1436 onViewOver : function(e, t){
1437 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1440 var item = this.view.findItemFromChild(t);
1443 var index = this.view.indexOf(item);
1444 this.select(index, false);
1449 onViewClick : function(view, doFocus, el, e)
1451 var index = this.view.getSelectedIndexes()[0];
1453 var r = this.store.getAt(index);
1457 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1464 Roo.each(this.tickItems, function(v,k){
1466 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1468 _this.tickItems.splice(k, 1);
1470 if(typeof(e) == 'undefined' && view == false){
1471 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1483 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1484 this.tickItems.push(r.data);
1487 if(typeof(e) == 'undefined' && view == false){
1488 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1495 this.onSelect(r, index);
1497 if(doFocus !== false && !this.blockFocus){
1498 this.inputEl().focus();
1503 restrictHeight : function(){
1504 //this.innerList.dom.style.height = '';
1505 //var inner = this.innerList.dom;
1506 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1507 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1508 //this.list.beginUpdate();
1509 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1510 this.list.alignTo(this.inputEl(), this.listAlign);
1511 this.list.alignTo(this.inputEl(), this.listAlign);
1512 //this.list.endUpdate();
1516 onEmptyResults : function(){
1518 if(this.tickable && this.editable){
1519 this.restrictHeight();
1527 * Returns true if the dropdown list is expanded, else false.
1529 isExpanded : function(){
1530 return this.list.isVisible();
1534 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1535 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1536 * @param {String} value The data value of the item to select
1537 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1538 * selected item if it is not currently in view (defaults to true)
1539 * @return {Boolean} True if the value matched an item in the list, else false
1541 selectByValue : function(v, scrollIntoView){
1542 if(v !== undefined && v !== null){
1543 var r = this.findRecord(this.valueField || this.displayField, v);
1545 this.select(this.store.indexOf(r), scrollIntoView);
1553 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1554 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1555 * @param {Number} index The zero-based index of the list item to select
1556 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1557 * selected item if it is not currently in view (defaults to true)
1559 select : function(index, scrollIntoView){
1560 this.selectedIndex = index;
1561 this.view.select(index);
1562 if(scrollIntoView !== false){
1563 var el = this.view.getNode(index);
1565 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1568 this.list.scrollChildIntoView(el, false);
1574 selectNext : function(){
1575 var ct = this.store.getCount();
1577 if(this.selectedIndex == -1){
1579 }else if(this.selectedIndex < ct-1){
1580 this.select(this.selectedIndex+1);
1586 selectPrev : function(){
1587 var ct = this.store.getCount();
1589 if(this.selectedIndex == -1){
1591 }else if(this.selectedIndex != 0){
1592 this.select(this.selectedIndex-1);
1598 onKeyUp : function(e){
1599 if(this.editable !== false && !e.isSpecialKey()){
1600 this.lastKey = e.getKey();
1601 this.dqTask.delay(this.queryDelay);
1606 validateBlur : function(){
1607 return !this.list || !this.list.isVisible();
1611 initQuery : function(){
1613 var v = this.getRawValue();
1615 if(this.tickable && this.editable){
1616 v = this.tickableInputEl().getValue();
1623 doForce : function(){
1624 if(this.inputEl().dom.value.length > 0){
1625 this.inputEl().dom.value =
1626 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1632 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1633 * query allowing the query action to be canceled if needed.
1634 * @param {String} query The SQL query to execute
1635 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1636 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1637 * saved in the current store (defaults to false)
1639 doQuery : function(q, forceAll){
1641 if(q === undefined || q === null){
1650 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1655 forceAll = qe.forceAll;
1656 if(forceAll === true || (q.length >= this.minChars)){
1658 this.hasQuery = true;
1660 if(this.lastQuery != q || this.alwaysQuery){
1662 if(this.mode == 'local'){
1663 this.selectedIndex = -1;
1665 this.store.clearFilter();
1668 if(this.specialFilter){
1669 this.fireEvent('specialfilter', this);
1674 this.store.filter(this.displayField, q);
1677 this.store.fireEvent("datachanged", this.store);
1684 this.store.baseParams[this.queryParam] = q;
1686 var options = {params : this.getParams(q)};
1690 options.params.start = this.page * this.pageSize;
1693 this.store.load(options);
1696 * this code will make the page width larger, at the beginning, the list not align correctly,
1697 * we should expand the list on onLoad
1703 this.selectedIndex = -1;
1708 this.loadNext = false;
1712 getParams : function(q){
1714 //p[this.queryParam] = q;
1718 p.limit = this.pageSize;
1724 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1726 collapse : function(){
1727 if(!this.isExpanded()){
1733 this.hasFocus = false;
1737 this.cancelBtn.hide();
1738 this.trigger.show();
1741 this.tickableInputEl().dom.value = '';
1742 this.tickableInputEl().blur();
1747 Roo.get(document).un('mousedown', this.collapseIf, this);
1748 Roo.get(document).un('mousewheel', this.collapseIf, this);
1749 if (!this.editable) {
1750 Roo.get(document).un('keydown', this.listKeyPress, this);
1752 this.fireEvent('collapse', this);
1758 collapseIf : function(e){
1759 var in_combo = e.within(this.el);
1760 var in_list = e.within(this.list);
1761 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1763 if (in_combo || in_list || is_list) {
1764 //e.stopPropagation();
1769 this.onTickableFooterButtonClick(e, false, false);
1777 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1779 expand : function(){
1781 if(this.isExpanded() || !this.hasFocus){
1785 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1786 this.list.setWidth(lw);
1792 this.restrictHeight();
1796 this.tickItems = Roo.apply([], this.item);
1799 this.cancelBtn.show();
1800 this.trigger.hide();
1803 this.tickableInputEl().focus();
1808 Roo.get(document).on('mousedown', this.collapseIf, this);
1809 Roo.get(document).on('mousewheel', this.collapseIf, this);
1810 if (!this.editable) {
1811 Roo.get(document).on('keydown', this.listKeyPress, this);
1814 this.fireEvent('expand', this);
1818 // Implements the default empty TriggerField.onTriggerClick function
1819 onTriggerClick : function(e)
1821 Roo.log('trigger click');
1823 if(this.disabled || !this.triggerList){
1828 this.loadNext = false;
1830 if(this.isExpanded()){
1832 if (!this.blockFocus) {
1833 this.inputEl().focus();
1837 this.hasFocus = true;
1838 if(this.triggerAction == 'all') {
1839 this.doQuery(this.allQuery, true);
1841 this.doQuery(this.getRawValue());
1843 if (!this.blockFocus) {
1844 this.inputEl().focus();
1849 onTickableTriggerClick : function(e)
1856 this.loadNext = false;
1857 this.hasFocus = true;
1859 if(this.triggerAction == 'all') {
1860 this.doQuery(this.allQuery, true);
1862 this.doQuery(this.getRawValue());
1866 onSearchFieldClick : function(e)
1868 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1869 this.onTickableFooterButtonClick(e, false, false);
1873 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1878 this.loadNext = false;
1879 this.hasFocus = true;
1881 if(this.triggerAction == 'all') {
1882 this.doQuery(this.allQuery, true);
1884 this.doQuery(this.getRawValue());
1888 listKeyPress : function(e)
1890 //Roo.log('listkeypress');
1891 // scroll to first matching element based on key pres..
1892 if (e.isSpecialKey()) {
1895 var k = String.fromCharCode(e.getKey()).toUpperCase();
1898 var csel = this.view.getSelectedNodes();
1899 var cselitem = false;
1901 var ix = this.view.indexOf(csel[0]);
1902 cselitem = this.store.getAt(ix);
1903 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1909 this.store.each(function(v) {
1911 // start at existing selection.
1912 if (cselitem.id == v.id) {
1918 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1919 match = this.store.indexOf(v);
1925 if (match === false) {
1926 return true; // no more action?
1929 this.view.select(match);
1930 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1931 sn.scrollIntoView(sn.dom.parentNode, false);
1934 onViewScroll : function(e, t){
1936 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){
1940 this.hasQuery = true;
1942 this.loading = this.list.select('.loading', true).first();
1944 if(this.loading === null){
1945 this.list.createChild({
1947 cls: 'loading roo-select2-more-results roo-select2-active',
1948 html: 'Loading more results...'
1951 this.loading = this.list.select('.loading', true).first();
1953 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1955 this.loading.hide();
1958 this.loading.show();
1963 this.loadNext = true;
1965 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1970 addItem : function(o)
1972 var dv = ''; // display value
1974 if (this.displayField) {
1975 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1977 // this is an error condition!!!
1978 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1985 var choice = this.choices.createChild({
1987 cls: 'roo-select2-search-choice',
1996 cls: 'roo-select2-search-choice-close',
2001 }, this.searchField);
2003 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2005 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2013 this.inputEl().dom.value = '';
2018 onRemoveItem : function(e, _self, o)
2022 this.lastItem = Roo.apply([], this.item);
2024 var index = this.item.indexOf(o.data) * 1;
2027 Roo.log('not this item?!');
2031 this.item.splice(index, 1);
2036 this.fireEvent('remove', this, e);
2042 syncValue : function()
2044 if(!this.item.length){
2051 Roo.each(this.item, function(i){
2052 if(_this.valueField){
2053 value.push(i[_this.valueField]);
2060 this.value = value.join(',');
2062 if(this.hiddenField){
2063 this.hiddenField.dom.value = this.value;
2066 this.store.fireEvent("datachanged", this.store);
2071 clearItem : function()
2079 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2087 if(this.tickable && !Roo.isTouch){
2088 this.view.refresh();
2092 inputEl: function ()
2094 if(Roo.isIOS && this.useNativeIOS){
2095 return this.el.select('select.roo-ios-select', true).first();
2098 if(Roo.isTouch && this.mobileTouchView){
2099 return this.el.select('input.form-control',true).first();
2103 return this.searchField;
2106 return this.el.select('input.form-control',true).first();
2109 onTickableFooterButtonClick : function(e, btn, el)
2113 this.lastItem = Roo.apply([], this.item);
2115 if(btn && btn.name == 'cancel'){
2116 this.tickItems = Roo.apply([], this.item);
2125 Roo.each(this.tickItems, function(o){
2133 validate : function()
2135 var v = this.getRawValue();
2138 v = this.getValue();
2141 if(this.disabled || this.allowBlank || v.length){
2150 tickableInputEl : function()
2152 if(!this.tickable || !this.editable){
2153 return this.inputEl();
2156 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2160 getAutoCreateTouchView : function()
2165 cls: 'form-group' //input-group
2171 type : this.inputType,
2172 cls : 'form-control x-combo-noedit',
2173 autocomplete: 'new-password',
2174 placeholder : this.placeholder || '',
2179 input.name = this.name;
2183 input.cls += ' input-' + this.size;
2186 if (this.disabled) {
2187 input.disabled = true;
2198 inputblock.cls += ' input-group';
2200 inputblock.cn.unshift({
2202 cls : 'input-group-addon',
2207 if(this.removable && !this.multiple){
2208 inputblock.cls += ' roo-removable';
2210 inputblock.cn.push({
2213 cls : 'roo-combo-removable-btn close'
2217 if(this.hasFeedback && !this.allowBlank){
2219 inputblock.cls += ' has-feedback';
2221 inputblock.cn.push({
2223 cls: 'glyphicon form-control-feedback'
2230 inputblock.cls += (this.before) ? '' : ' input-group';
2232 inputblock.cn.push({
2234 cls : 'input-group-addon',
2245 cls: 'form-hidden-field'
2259 cls: 'form-hidden-field'
2263 cls: 'roo-select2-choices',
2267 cls: 'roo-select2-search-field',
2280 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2286 if(!this.multiple && this.showToggleBtn){
2293 if (this.caret != false) {
2296 cls: 'fa fa-' + this.caret
2303 cls : 'input-group-addon btn dropdown-toggle',
2308 cls: 'combobox-clear',
2322 combobox.cls += ' roo-select2-container-multi';
2325 var align = this.labelAlign || this.parentLabelAlign();
2327 if (align ==='left' && this.fieldLabel.length) {
2332 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2333 tooltip : 'This field is required'
2337 cls : 'control-label',
2338 html : this.fieldLabel
2349 var labelCfg = cfg.cn[1];
2350 var contentCfg = cfg.cn[2];
2353 if(this.indicatorpos == 'right'){
2357 cls : 'control-label',
2358 html : this.fieldLabel
2363 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2364 tooltip : 'This field is required'
2375 labelCfg = cfg.cn[0];
2376 contentCfg = cfg.cn[2];
2378 if(this.labelWidth > 12){
2379 labelCfg.style = "width: " + this.labelWidth + 'px';
2382 if(this.labelWidth < 13 && this.labelmd == 0){
2383 this.labelmd = this.labelWidth;
2386 if(this.labellg > 0){
2387 labelCfg.cls += ' col-lg-' + this.labellg;
2388 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2391 if(this.labelmd > 0){
2392 labelCfg.cls += ' col-md-' + this.labelmd;
2393 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2396 if(this.labelsm > 0){
2397 labelCfg.cls += ' col-sm-' + this.labelsm;
2398 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2401 if(this.labelxs > 0){
2402 labelCfg.cls += ' col-xs-' + this.labelxs;
2403 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2407 } else if ( this.fieldLabel.length) {
2411 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2412 tooltip : 'This field is required'
2416 cls : 'control-label',
2417 html : this.fieldLabel
2428 if(this.indicatorpos == 'right'){
2432 cls : 'control-label',
2433 html : this.fieldLabel
2438 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2439 tooltip : 'This field is required'
2454 var settings = this;
2456 ['xs','sm','md','lg'].map(function(size){
2457 if (settings[size]) {
2458 cfg.cls += ' col-' + size + '-' + settings[size];
2465 initTouchView : function()
2467 this.renderTouchView();
2469 this.touchViewEl.on('scroll', function(){
2470 this.el.dom.scrollTop = 0;
2473 this.originalValue = this.getValue();
2475 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2477 this.inputEl().on("click", this.showTouchView, this);
2478 if (this.triggerEl) {
2479 this.triggerEl.on("click", this.showTouchView, this);
2483 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2484 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2486 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2488 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2489 this.store.on('load', this.onTouchViewLoad, this);
2490 this.store.on('loadexception', this.onTouchViewLoadException, this);
2492 if(this.hiddenName){
2494 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2496 this.hiddenField.dom.value =
2497 this.hiddenValue !== undefined ? this.hiddenValue :
2498 this.value !== undefined ? this.value : '';
2500 this.el.dom.removeAttribute('name');
2501 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2505 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2506 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2509 if(this.removable && !this.multiple){
2510 var close = this.closeTriggerEl();
2512 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2513 close.on('click', this.removeBtnClick, this, close);
2517 * fix the bug in Safari iOS8
2519 this.inputEl().on("focus", function(e){
2520 document.activeElement.blur();
2528 renderTouchView : function()
2530 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2531 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2533 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2534 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2536 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2537 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2538 this.touchViewBodyEl.setStyle('overflow', 'auto');
2540 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2541 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2543 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2544 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2548 showTouchView : function()
2554 this.touchViewHeaderEl.hide();
2556 if(this.modalTitle.length){
2557 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2558 this.touchViewHeaderEl.show();
2561 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2562 this.touchViewEl.show();
2564 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2565 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2566 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2568 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2570 if(this.modalTitle.length){
2571 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2574 this.touchViewBodyEl.setHeight(bodyHeight);
2578 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2580 this.touchViewEl.addClass('in');
2583 this.doTouchViewQuery();
2587 hideTouchView : function()
2589 this.touchViewEl.removeClass('in');
2593 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2595 this.touchViewEl.setStyle('display', 'none');
2600 setTouchViewValue : function()
2607 Roo.each(this.tickItems, function(o){
2612 this.hideTouchView();
2615 doTouchViewQuery : function()
2624 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2628 if(!this.alwaysQuery || this.mode == 'local'){
2629 this.onTouchViewLoad();
2636 onTouchViewBeforeLoad : function(combo,opts)
2642 onTouchViewLoad : function()
2644 if(this.store.getCount() < 1){
2645 this.onTouchViewEmptyResults();
2649 this.clearTouchView();
2651 var rawValue = this.getRawValue();
2653 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2655 this.tickItems = [];
2657 this.store.data.each(function(d, rowIndex){
2658 var row = this.touchViewListGroup.createChild(template);
2660 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2661 row.addClass(d.data.cls);
2664 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2667 html : d.data[this.displayField]
2670 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2671 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2674 row.removeClass('selected');
2675 if(!this.multiple && this.valueField &&
2676 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2679 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2680 row.addClass('selected');
2683 if(this.multiple && this.valueField &&
2684 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2688 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2689 this.tickItems.push(d.data);
2692 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2696 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2698 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2700 if(this.modalTitle.length){
2701 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2704 var listHeight = this.touchViewListGroup.getHeight();
2708 if(firstChecked && listHeight > bodyHeight){
2709 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2714 onTouchViewLoadException : function()
2716 this.hideTouchView();
2719 onTouchViewEmptyResults : function()
2721 this.clearTouchView();
2723 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2725 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2729 clearTouchView : function()
2731 this.touchViewListGroup.dom.innerHTML = '';
2734 onTouchViewClick : function(e, el, o)
2739 var rowIndex = o.rowIndex;
2741 var r = this.store.getAt(rowIndex);
2743 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2746 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2747 c.dom.removeAttribute('checked');
2750 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2752 this.setFromData(r.data);
2754 var close = this.closeTriggerEl();
2760 this.hideTouchView();
2762 this.fireEvent('select', this, r, rowIndex);
2767 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2768 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2769 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2773 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2774 this.addItem(r.data);
2775 this.tickItems.push(r.data);
2779 getAutoCreateNativeIOS : function()
2782 cls: 'form-group' //input-group,
2787 cls : 'roo-ios-select'
2791 combobox.name = this.name;
2794 if (this.disabled) {
2795 combobox.disabled = true;
2798 var settings = this;
2800 ['xs','sm','md','lg'].map(function(size){
2801 if (settings[size]) {
2802 cfg.cls += ' col-' + size + '-' + settings[size];
2812 initIOSView : function()
2814 this.store.on('load', this.onIOSViewLoad, this);
2819 onIOSViewLoad : function()
2821 if(this.store.getCount() < 1){
2825 this.clearIOSView();
2827 if(this.allowBlank) {
2829 var default_text = '-- SELECT --';
2831 var opt = this.inputEl().createChild({
2838 o[this.valueField] = 0;
2839 o[this.displayField] = default_text;
2841 this.ios_options.push({
2848 this.store.data.each(function(d, rowIndex){
2852 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2853 html = d.data[this.displayField];
2858 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2859 value = d.data[this.valueField];
2868 if(this.value == d.data[this.valueField]){
2869 option['selected'] = true;
2872 var opt = this.inputEl().createChild(option);
2874 this.ios_options.push({
2881 this.inputEl().on('change', function(){
2882 this.fireEvent('select', this);
2887 clearIOSView: function()
2889 this.inputEl().dom.innerHTML = '';
2891 this.ios_options = [];
2894 setIOSValue: function(v)
2898 if(!this.ios_options){
2902 Roo.each(this.ios_options, function(opts){
2904 opts.el.dom.removeAttribute('selected');
2906 if(opts.data[this.valueField] != v){
2910 opts.el.dom.setAttribute('selected', true);
2916 * @cfg {Boolean} grow
2920 * @cfg {Number} growMin
2924 * @cfg {Number} growMax
2933 Roo.apply(Roo.bootstrap.ComboBox, {
2937 cls: 'modal-header',
2959 cls: 'list-group-item',
2963 cls: 'roo-combobox-list-group-item-value'
2967 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2981 listItemCheckbox : {
2983 cls: 'list-group-item',
2987 cls: 'roo-combobox-list-group-item-value'
2991 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3007 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3012 cls: 'modal-footer',
3020 cls: 'col-xs-6 text-left',
3023 cls: 'btn btn-danger roo-touch-view-cancel',
3029 cls: 'col-xs-6 text-right',
3032 cls: 'btn btn-success roo-touch-view-ok',
3043 Roo.apply(Roo.bootstrap.ComboBox, {
3045 touchViewTemplate : {
3047 cls: 'modal fade roo-combobox-touch-view',
3051 cls: 'modal-dialog',
3052 style : 'position:fixed', // we have to fix position....
3056 cls: 'modal-content',
3058 Roo.bootstrap.ComboBox.header,
3059 Roo.bootstrap.ComboBox.body,
3060 Roo.bootstrap.ComboBox.footer