7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
19 * @cfg {String} emptyTitle default ''
21 * Create a new ComboBox.
22 * @param {Object} config Configuration options
24 Roo.bootstrap.ComboBox = function(config){
25 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
29 * Fires when the dropdown list is expanded
30 * @param {Roo.bootstrap.ComboBox} combo This combo box
35 * Fires when the dropdown list is collapsed
36 * @param {Roo.bootstrap.ComboBox} combo This combo box
41 * Fires before a list item is selected. Return false to cancel the selection.
42 * @param {Roo.bootstrap.ComboBox} combo This combo box
43 * @param {Roo.data.Record} record The data record returned from the underlying store
44 * @param {Number} index The index of the selected item in the dropdown list
46 'beforeselect' : true,
49 * Fires when a list item is selected
50 * @param {Roo.bootstrap.ComboBox} combo This combo box
51 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
52 * @param {Number} index The index of the selected item in the dropdown list
57 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
58 * The event object passed has these properties:
59 * @param {Roo.bootstrap.ComboBox} combo This combo box
60 * @param {String} query The query
61 * @param {Boolean} forceAll true to force "all" query
62 * @param {Boolean} cancel true to cancel the query
63 * @param {Object} e The query event object
68 * Fires when the 'add' icon is pressed (add a listener to enable add button)
69 * @param {Roo.bootstrap.ComboBox} combo This combo box
74 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
75 * @param {Roo.bootstrap.ComboBox} combo This combo box
76 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
81 * Fires when the remove value from the combobox array
82 * @param {Roo.bootstrap.ComboBox} combo This combo box
87 * Fires when the remove value from the combobox array
88 * @param {Roo.bootstrap.ComboBox} combo This combo box
92 * @event specialfilter
93 * Fires when specialfilter
94 * @param {Roo.bootstrap.ComboBox} combo This combo box
96 'specialfilter' : true,
99 * Fires when tick the element
100 * @param {Roo.bootstrap.ComboBox} combo This combo box
104 * @event touchviewdisplay
105 * Fires when touch view require special display (default is using displayField)
106 * @param {Roo.bootstrap.ComboBox} combo This combo box
107 * @param {Object} cfg set html .
109 'touchviewdisplay' : true
116 this.selectedIndex = -1;
117 if(this.mode == 'local'){
118 if(config.queryDelay === undefined){
119 this.queryDelay = 10;
121 if(config.minChars === undefined){
127 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
130 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
131 * rendering into an Roo.Editor, defaults to false)
134 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
135 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
138 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
141 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
142 * the dropdown list (defaults to undefined, with no header element)
146 * @cfg {String/Roo.Template} tpl The template to use to render the output
150 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
152 listWidth: undefined,
154 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
155 * mode = 'remote' or 'text' if mode = 'local')
157 displayField: undefined,
160 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
161 * mode = 'remote' or 'value' if mode = 'local').
162 * Note: use of a valueField requires the user make a selection
163 * in order for a value to be mapped.
165 valueField: undefined,
167 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
172 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
173 * field's data value (defaults to the underlying DOM element's name)
175 hiddenName: undefined,
177 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
181 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
183 selectedClass: 'active',
186 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
190 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
191 * anchor positions (defaults to 'tl-bl')
195 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
199 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
200 * query specified by the allQuery config option (defaults to 'query')
202 triggerAction: 'query',
204 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
205 * (defaults to 4, does not apply if editable = false)
209 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
210 * delay (typeAheadDelay) if it matches a known value (defaults to false)
214 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
215 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
219 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
220 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
224 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
225 * when editable = true (defaults to false)
229 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
233 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
234 * when mode = 'remote' (defaults to 'Loading...')
236 loadingText: 'Loading...',
238 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
242 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
246 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
247 * traditional select (defaults to true)
251 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
255 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
259 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
260 * listWidth has a higher value)
264 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
265 * allow the user to set arbitrary text into the field (defaults to false)
267 forceSelection:false,
269 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
270 * if typeAhead = true (defaults to 250)
272 typeAheadDelay : 250,
274 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
275 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
277 valueNotFoundText : undefined,
279 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
284 * @cfg {Boolean} disableClear Disable showing of clear button.
286 disableClear : false,
288 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
293 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
298 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
300 invalidClass : "has-warning",
303 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
305 validClass : "has-success",
308 * @cfg {Boolean} specialFilter (true|false) special filter default false
310 specialFilter : false,
313 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
315 mobileTouchView : true,
318 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
320 useNativeIOS : false,
334 btnPosition : 'right',
336 showToggleBtn : true,
338 emptyResultText: 'Empty',
339 triggerText : 'Select',
342 // element that contains real text value.. (when hidden is used..)
344 getAutoCreate : function()
349 * Render classic select for iso
352 if(Roo.isIOS && this.useNativeIOS){
353 cfg = this.getAutoCreateNativeIOS();
361 if(Roo.isTouch && this.mobileTouchView){
362 cfg = this.getAutoCreateTouchView();
370 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
375 * ComboBox with tickable selections
378 var align = this.labelAlign || this.parentLabelAlign();
381 cls : 'form-group roo-combobox-tickable' //input-group
384 var btn_text_select = '';
385 var btn_text_done = '';
386 var btn_text_cancel = '';
388 if (this.btn_text_show) {
389 btn_text_select = 'Select';
390 btn_text_done = 'Done';
391 btn_text_cancel = 'Cancel';
396 cls : 'tickable-buttons',
401 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
402 //html : this.triggerText
403 html: btn_text_select
409 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
417 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
419 html: btn_text_cancel
427 cls: 'roo-select2-search-field-input'
433 Roo.each(buttons.cn, function(c){
435 c.cls += ' btn-' + _this.size;
438 if (_this.disabled) {
449 cls: 'form-hidden-field'
453 cls: 'roo-select2-choices',
457 cls: 'roo-select2-search-field',
468 cls: 'roo-select2-container input-group roo-select2-container-multi',
473 // cls: 'typeahead typeahead-long dropdown-menu',
474 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
479 if(this.hasFeedback && !this.allowBlank){
483 cls: 'glyphicon form-control-feedback'
486 combobox.cn.push(feedback);
490 if (align ==='left' && this.fieldLabel.length) {
492 cfg.cls += ' roo-form-group-label-left';
497 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
498 tooltip : 'This field is required'
503 cls : 'control-label',
504 html : this.fieldLabel
516 var labelCfg = cfg.cn[1];
517 var contentCfg = cfg.cn[2];
520 if(this.indicatorpos == 'right'){
526 cls : 'control-label',
530 html : this.fieldLabel
534 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
535 tooltip : 'This field is required'
550 labelCfg = cfg.cn[0];
551 contentCfg = cfg.cn[1];
555 if(this.labelWidth > 12){
556 labelCfg.style = "width: " + this.labelWidth + 'px';
559 if(this.labelWidth < 13 && this.labelmd == 0){
560 this.labelmd = this.labelWidth;
563 if(this.labellg > 0){
564 labelCfg.cls += ' col-lg-' + this.labellg;
565 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
568 if(this.labelmd > 0){
569 labelCfg.cls += ' col-md-' + this.labelmd;
570 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
573 if(this.labelsm > 0){
574 labelCfg.cls += ' col-sm-' + this.labelsm;
575 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
578 if(this.labelxs > 0){
579 labelCfg.cls += ' col-xs-' + this.labelxs;
580 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
584 } else if ( this.fieldLabel.length) {
585 // Roo.log(" label");
589 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
590 tooltip : 'This field is required'
594 //cls : 'input-group-addon',
595 html : this.fieldLabel
600 if(this.indicatorpos == 'right'){
604 //cls : 'input-group-addon',
605 html : this.fieldLabel
609 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
610 tooltip : 'This field is required'
619 // Roo.log(" no label && no align");
626 ['xs','sm','md','lg'].map(function(size){
627 if (settings[size]) {
628 cfg.cls += ' col-' + size + '-' + settings[size];
636 _initEventsCalled : false,
639 initEvents: function()
641 if (this._initEventsCalled) { // as we call render... prevent looping...
644 this._initEventsCalled = true;
647 throw "can not find store for combo";
650 this.store = Roo.factory(this.store, Roo.data);
651 this.store.parent = this;
653 // if we are building from html. then this element is so complex, that we can not really
654 // use the rendered HTML.
655 // so we have to trash and replace the previous code.
656 if (Roo.XComponent.build_from_html) {
658 // remove this element....
659 var e = this.el.dom, k=0;
660 while (e ) { e = e.previousSibling; ++k;}
665 this.rendered = false;
667 this.render(this.parent().getChildContainer(true), k);
673 if(Roo.isIOS && this.useNativeIOS){
682 if(Roo.isTouch && this.mobileTouchView){
683 this.initTouchView();
688 this.initTickableEvents();
692 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
696 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
698 this.hiddenField.dom.value =
699 this.hiddenValue !== undefined ? this.hiddenValue :
700 this.value !== undefined ? this.value : '';
702 // prevent input submission
703 this.el.dom.removeAttribute('name');
704 this.hiddenField.dom.setAttribute('name', this.hiddenName);
709 // this.el.dom.setAttribute('autocomplete', 'off');
712 var cls = 'x-combo-list';
714 //this.list = new Roo.Layer({
715 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
721 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
722 _this.list.setWidth(lw);
725 this.list.on('mouseover', this.onViewOver, this);
726 this.list.on('mousemove', this.onViewMove, this);
728 this.list.on('scroll', this.onViewScroll, this);
731 this.list.swallowEvent('mousewheel');
732 this.assetHeight = 0;
735 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
736 this.assetHeight += this.header.getHeight();
739 this.innerList = this.list.createChild({cls:cls+'-inner'});
740 this.innerList.on('mouseover', this.onViewOver, this);
741 this.innerList.on('mousemove', this.onViewMove, this);
742 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
744 if(this.allowBlank && !this.pageSize && !this.disableClear){
745 this.footer = this.list.createChild({cls:cls+'-ft'});
746 this.pageTb = new Roo.Toolbar(this.footer);
750 this.footer = this.list.createChild({cls:cls+'-ft'});
751 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
752 {pageSize: this.pageSize});
756 if (this.pageTb && this.allowBlank && !this.disableClear) {
758 this.pageTb.add(new Roo.Toolbar.Fill(), {
759 cls: 'x-btn-icon x-btn-clear',
765 _this.onSelect(false, -1);
770 this.assetHeight += this.footer.getHeight();
775 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
778 this.view = new Roo.View(this.list, this.tpl, {
779 singleSelect:true, store: this.store, selectedClass: this.selectedClass
781 //this.view.wrapEl.setDisplayed(false);
782 this.view.on('click', this.onViewClick, this);
785 this.store.on('beforeload', this.onBeforeLoad, this);
786 this.store.on('load', this.onLoad, this);
787 this.store.on('loadexception', this.onLoadException, this);
790 this.resizer = new Roo.Resizable(this.list, {
791 pinned:true, handles:'se'
793 this.resizer.on('resize', function(r, w, h){
794 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
796 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
797 this.restrictHeight();
799 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
803 this.editable = true;
804 this.setEditable(false);
809 if (typeof(this.events.add.listeners) != 'undefined') {
811 this.addicon = this.wrap.createChild(
812 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
814 this.addicon.on('click', function(e) {
815 this.fireEvent('add', this);
818 if (typeof(this.events.edit.listeners) != 'undefined') {
820 this.editicon = this.wrap.createChild(
821 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
823 this.editicon.setStyle('margin-left', '40px');
825 this.editicon.on('click', function(e) {
827 // we fire even if inothing is selected..
828 this.fireEvent('edit', this, this.lastData );
834 this.keyNav = new Roo.KeyNav(this.inputEl(), {
836 this.inKeyMode = true;
840 "down" : function(e){
841 if(!this.isExpanded()){
842 this.onTriggerClick();
844 this.inKeyMode = true;
849 "enter" : function(e){
850 // this.onViewClick();
854 if(this.fireEvent("specialkey", this, e)){
855 this.onViewClick(false);
868 if(this.fireEvent("specialkey", this, e)){
869 this.onViewClick(false);
877 doRelay : function(foo, bar, hname){
878 if(hname == 'down' || this.scope.isExpanded()){
879 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
888 this.queryDelay = Math.max(this.queryDelay || 10,
889 this.mode == 'local' ? 10 : 250);
892 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
895 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
897 if(this.editable !== false){
898 this.inputEl().on("keyup", this.onKeyUp, this);
900 if(this.forceSelection){
901 this.inputEl().on('blur', this.doForce, this);
905 this.choices = this.el.select('ul.roo-select2-choices', true).first();
906 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
910 initTickableEvents: function()
916 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
918 this.hiddenField.dom.value =
919 this.hiddenValue !== undefined ? this.hiddenValue :
920 this.value !== undefined ? this.value : '';
922 // prevent input submission
923 this.el.dom.removeAttribute('name');
924 this.hiddenField.dom.setAttribute('name', this.hiddenName);
929 // this.list = this.el.select('ul.dropdown-menu',true).first();
931 this.choices = this.el.select('ul.roo-select2-choices', true).first();
932 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
933 if(this.triggerList){
934 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
937 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
938 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
940 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
941 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
943 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
944 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
946 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
947 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
948 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
951 this.cancelBtn.hide();
956 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
957 _this.list.setWidth(lw);
960 this.list.on('mouseover', this.onViewOver, this);
961 this.list.on('mousemove', this.onViewMove, this);
963 this.list.on('scroll', this.onViewScroll, this);
966 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>';
969 this.view = new Roo.View(this.list, this.tpl, {
970 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
973 //this.view.wrapEl.setDisplayed(false);
974 this.view.on('click', this.onViewClick, this);
978 this.store.on('beforeload', this.onBeforeLoad, this);
979 this.store.on('load', this.onLoad, this);
980 this.store.on('loadexception', this.onLoadException, this);
983 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
985 this.inKeyMode = true;
989 "down" : function(e){
990 this.inKeyMode = true;
994 "enter" : function(e){
995 if(this.fireEvent("specialkey", this, e)){
996 this.onViewClick(false);
1002 "esc" : function(e){
1003 this.onTickableFooterButtonClick(e, false, false);
1006 "tab" : function(e){
1007 this.fireEvent("specialkey", this, e);
1009 this.onTickableFooterButtonClick(e, false, false);
1016 doRelay : function(e, fn, key){
1017 if(this.scope.isExpanded()){
1018 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1027 this.queryDelay = Math.max(this.queryDelay || 10,
1028 this.mode == 'local' ? 10 : 250);
1031 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1034 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1037 if(this.editable !== false){
1038 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1041 this.indicator = this.indicatorEl();
1044 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1045 this.indicator.hide();
1050 onDestroy : function(){
1052 this.view.setStore(null);
1053 this.view.el.removeAllListeners();
1054 this.view.el.remove();
1055 this.view.purgeListeners();
1058 this.list.dom.innerHTML = '';
1062 this.store.un('beforeload', this.onBeforeLoad, this);
1063 this.store.un('load', this.onLoad, this);
1064 this.store.un('loadexception', this.onLoadException, this);
1066 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1070 fireKey : function(e){
1071 if(e.isNavKeyPress() && !this.list.isVisible()){
1072 this.fireEvent("specialkey", this, e);
1077 onResize: function(w, h){
1078 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1080 // if(typeof w != 'number'){
1081 // // we do not handle it!?!?
1084 // var tw = this.trigger.getWidth();
1085 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1086 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1088 // this.inputEl().setWidth( this.adjustWidth('input', x));
1090 // //this.trigger.setStyle('left', x+'px');
1092 // if(this.list && this.listWidth === undefined){
1093 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1094 // this.list.setWidth(lw);
1095 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1103 * Allow or prevent the user from directly editing the field text. If false is passed,
1104 * the user will only be able to select from the items defined in the dropdown list. This method
1105 * is the runtime equivalent of setting the 'editable' config option at config time.
1106 * @param {Boolean} value True to allow the user to directly edit the field text
1108 setEditable : function(value){
1109 if(value == this.editable){
1112 this.editable = value;
1114 this.inputEl().dom.setAttribute('readOnly', true);
1115 this.inputEl().on('mousedown', this.onTriggerClick, this);
1116 this.inputEl().addClass('x-combo-noedit');
1118 this.inputEl().dom.setAttribute('readOnly', false);
1119 this.inputEl().un('mousedown', this.onTriggerClick, this);
1120 this.inputEl().removeClass('x-combo-noedit');
1126 onBeforeLoad : function(combo,opts){
1131 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1133 this.restrictHeight();
1134 this.selectedIndex = -1;
1138 onLoad : function(){
1140 this.hasQuery = false;
1146 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1147 this.loading.hide();
1150 if(this.store.getCount() > 0){
1153 this.restrictHeight();
1154 if(this.lastQuery == this.allQuery){
1155 if(this.editable && !this.tickable){
1156 this.inputEl().dom.select();
1160 !this.selectByValue(this.value, true) &&
1163 !this.store.lastOptions ||
1164 typeof(this.store.lastOptions.add) == 'undefined' ||
1165 this.store.lastOptions.add != true
1168 this.select(0, true);
1174 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1175 this.taTask.delay(this.typeAheadDelay);
1179 this.onEmptyResults();
1185 onLoadException : function()
1187 this.hasQuery = false;
1189 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1190 this.loading.hide();
1193 if(this.tickable && this.editable){
1198 // only causes errors at present
1199 //Roo.log(this.store.reader.jsonData);
1200 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1202 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1208 onTypeAhead : function(){
1209 if(this.store.getCount() > 0){
1210 var r = this.store.getAt(0);
1211 var newValue = r.data[this.displayField];
1212 var len = newValue.length;
1213 var selStart = this.getRawValue().length;
1215 if(selStart != len){
1216 this.setRawValue(newValue);
1217 this.selectText(selStart, newValue.length);
1223 onSelect : function(record, index){
1225 if(this.fireEvent('beforeselect', this, record, index) !== false){
1227 this.setFromData(index > -1 ? record.data : false);
1230 this.fireEvent('select', this, record, index);
1235 * Returns the currently selected field value or empty string if no value is set.
1236 * @return {String} value The selected value
1238 getValue : function()
1240 if(Roo.isIOS && this.useNativeIOS){
1241 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1245 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1248 if(this.valueField){
1249 return typeof this.value != 'undefined' ? this.value : '';
1251 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1255 getRawValue : function()
1257 if(Roo.isIOS && this.useNativeIOS){
1258 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1261 var v = this.inputEl().getValue();
1267 * Clears any text/value currently set in the field
1269 clearValue : function(){
1271 if(this.hiddenField){
1272 this.hiddenField.dom.value = '';
1275 this.setRawValue('');
1276 this.lastSelectionText = '';
1277 this.lastData = false;
1279 var close = this.closeTriggerEl();
1290 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1291 * will be displayed in the field. If the value does not match the data value of an existing item,
1292 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1293 * Otherwise the field will be blank (although the value will still be set).
1294 * @param {String} value The value to match
1296 setValue : function(v)
1298 if(Roo.isIOS && this.useNativeIOS){
1299 this.setIOSValue(v);
1309 if(this.valueField){
1310 var r = this.findRecord(this.valueField, v);
1312 text = r.data[this.displayField];
1313 }else if(this.valueNotFoundText !== undefined){
1314 text = this.valueNotFoundText;
1317 this.lastSelectionText = text;
1318 if(this.hiddenField){
1319 this.hiddenField.dom.value = v;
1321 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1324 var close = this.closeTriggerEl();
1327 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1333 * @property {Object} the last set data for the element
1338 * Sets the value of the field based on a object which is related to the record format for the store.
1339 * @param {Object} value the value to set as. or false on reset?
1341 setFromData : function(o){
1348 var dv = ''; // display value
1349 var vv = ''; // value value..
1351 if (this.displayField) {
1352 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1354 // this is an error condition!!!
1355 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1358 if(this.valueField){
1359 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1362 var close = this.closeTriggerEl();
1365 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1368 if(this.hiddenField){
1369 this.hiddenField.dom.value = vv;
1371 this.lastSelectionText = dv;
1372 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1376 // no hidden field.. - we store the value in 'value', but still display
1377 // display field!!!!
1378 this.lastSelectionText = dv;
1379 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1387 // overridden so that last data is reset..
1394 this.setValue(this.originalValue);
1395 //this.clearInvalid();
1396 this.lastData = false;
1398 this.view.clearSelections();
1404 findRecord : function(prop, value){
1406 if(this.store.getCount() > 0){
1407 this.store.each(function(r){
1408 if(r.data[prop] == value){
1420 // returns hidden if it's set..
1421 if (!this.rendered) {return ''};
1422 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1426 onViewMove : function(e, t){
1427 this.inKeyMode = false;
1431 onViewOver : function(e, t){
1432 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1435 var item = this.view.findItemFromChild(t);
1438 var index = this.view.indexOf(item);
1439 this.select(index, false);
1444 onViewClick : function(view, doFocus, el, e)
1446 var index = this.view.getSelectedIndexes()[0];
1448 var r = this.store.getAt(index);
1452 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1459 Roo.each(this.tickItems, function(v,k){
1461 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1463 _this.tickItems.splice(k, 1);
1465 if(typeof(e) == 'undefined' && view == false){
1466 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1478 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1479 this.tickItems.push(r.data);
1482 if(typeof(e) == 'undefined' && view == false){
1483 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1490 this.onSelect(r, index);
1492 if(doFocus !== false && !this.blockFocus){
1493 this.inputEl().focus();
1498 restrictHeight : function(){
1499 //this.innerList.dom.style.height = '';
1500 //var inner = this.innerList.dom;
1501 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1502 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1503 //this.list.beginUpdate();
1504 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1505 this.list.alignTo(this.inputEl(), this.listAlign);
1506 this.list.alignTo(this.inputEl(), this.listAlign);
1507 //this.list.endUpdate();
1511 onEmptyResults : function(){
1513 if(this.tickable && this.editable){
1514 this.restrictHeight();
1522 * Returns true if the dropdown list is expanded, else false.
1524 isExpanded : function(){
1525 return this.list.isVisible();
1529 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1530 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1531 * @param {String} value The data value of the item to select
1532 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1533 * selected item if it is not currently in view (defaults to true)
1534 * @return {Boolean} True if the value matched an item in the list, else false
1536 selectByValue : function(v, scrollIntoView){
1537 if(v !== undefined && v !== null){
1538 var r = this.findRecord(this.valueField || this.displayField, v);
1540 this.select(this.store.indexOf(r), scrollIntoView);
1548 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1549 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1550 * @param {Number} index The zero-based index of the list item to select
1551 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1552 * selected item if it is not currently in view (defaults to true)
1554 select : function(index, scrollIntoView){
1555 this.selectedIndex = index;
1556 this.view.select(index);
1557 if(scrollIntoView !== false){
1558 var el = this.view.getNode(index);
1560 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1563 this.list.scrollChildIntoView(el, false);
1569 selectNext : function(){
1570 var ct = this.store.getCount();
1572 if(this.selectedIndex == -1){
1574 }else if(this.selectedIndex < ct-1){
1575 this.select(this.selectedIndex+1);
1581 selectPrev : function(){
1582 var ct = this.store.getCount();
1584 if(this.selectedIndex == -1){
1586 }else if(this.selectedIndex != 0){
1587 this.select(this.selectedIndex-1);
1593 onKeyUp : function(e){
1594 if(this.editable !== false && !e.isSpecialKey()){
1595 this.lastKey = e.getKey();
1596 this.dqTask.delay(this.queryDelay);
1601 validateBlur : function(){
1602 return !this.list || !this.list.isVisible();
1606 initQuery : function(){
1608 var v = this.getRawValue();
1610 if(this.tickable && this.editable){
1611 v = this.tickableInputEl().getValue();
1618 doForce : function(){
1619 if(this.inputEl().dom.value.length > 0){
1620 this.inputEl().dom.value =
1621 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1627 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1628 * query allowing the query action to be canceled if needed.
1629 * @param {String} query The SQL query to execute
1630 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1631 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1632 * saved in the current store (defaults to false)
1634 doQuery : function(q, forceAll){
1636 if(q === undefined || q === null){
1645 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1650 forceAll = qe.forceAll;
1651 if(forceAll === true || (q.length >= this.minChars)){
1653 this.hasQuery = true;
1655 if(this.lastQuery != q || this.alwaysQuery){
1657 if(this.mode == 'local'){
1658 this.selectedIndex = -1;
1660 this.store.clearFilter();
1663 if(this.specialFilter){
1664 this.fireEvent('specialfilter', this);
1669 this.store.filter(this.displayField, q);
1672 this.store.fireEvent("datachanged", this.store);
1679 this.store.baseParams[this.queryParam] = q;
1681 var options = {params : this.getParams(q)};
1685 options.params.start = this.page * this.pageSize;
1688 this.store.load(options);
1691 * this code will make the page width larger, at the beginning, the list not align correctly,
1692 * we should expand the list on onLoad
1698 this.selectedIndex = -1;
1703 this.loadNext = false;
1707 getParams : function(q){
1709 //p[this.queryParam] = q;
1713 p.limit = this.pageSize;
1719 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1721 collapse : function(){
1722 if(!this.isExpanded()){
1728 this.hasFocus = false;
1732 this.cancelBtn.hide();
1733 this.trigger.show();
1736 this.tickableInputEl().dom.value = '';
1737 this.tickableInputEl().blur();
1742 Roo.get(document).un('mousedown', this.collapseIf, this);
1743 Roo.get(document).un('mousewheel', this.collapseIf, this);
1744 if (!this.editable) {
1745 Roo.get(document).un('keydown', this.listKeyPress, this);
1747 this.fireEvent('collapse', this);
1753 collapseIf : function(e){
1754 var in_combo = e.within(this.el);
1755 var in_list = e.within(this.list);
1756 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1758 if (in_combo || in_list || is_list) {
1759 //e.stopPropagation();
1764 this.onTickableFooterButtonClick(e, false, false);
1772 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1774 expand : function(){
1776 if(this.isExpanded() || !this.hasFocus){
1780 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1781 this.list.setWidth(lw);
1787 this.restrictHeight();
1791 this.tickItems = Roo.apply([], this.item);
1794 this.cancelBtn.show();
1795 this.trigger.hide();
1798 this.tickableInputEl().focus();
1803 Roo.get(document).on('mousedown', this.collapseIf, this);
1804 Roo.get(document).on('mousewheel', this.collapseIf, this);
1805 if (!this.editable) {
1806 Roo.get(document).on('keydown', this.listKeyPress, this);
1809 this.fireEvent('expand', this);
1813 // Implements the default empty TriggerField.onTriggerClick function
1814 onTriggerClick : function(e)
1816 Roo.log('trigger click');
1818 if(this.disabled || !this.triggerList){
1823 this.loadNext = false;
1825 if(this.isExpanded()){
1827 if (!this.blockFocus) {
1828 this.inputEl().focus();
1832 this.hasFocus = true;
1833 if(this.triggerAction == 'all') {
1834 this.doQuery(this.allQuery, true);
1836 this.doQuery(this.getRawValue());
1838 if (!this.blockFocus) {
1839 this.inputEl().focus();
1844 onTickableTriggerClick : function(e)
1851 this.loadNext = false;
1852 this.hasFocus = true;
1854 if(this.triggerAction == 'all') {
1855 this.doQuery(this.allQuery, true);
1857 this.doQuery(this.getRawValue());
1861 onSearchFieldClick : function(e)
1863 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1864 this.onTickableFooterButtonClick(e, false, false);
1868 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1873 this.loadNext = false;
1874 this.hasFocus = true;
1876 if(this.triggerAction == 'all') {
1877 this.doQuery(this.allQuery, true);
1879 this.doQuery(this.getRawValue());
1883 listKeyPress : function(e)
1885 //Roo.log('listkeypress');
1886 // scroll to first matching element based on key pres..
1887 if (e.isSpecialKey()) {
1890 var k = String.fromCharCode(e.getKey()).toUpperCase();
1893 var csel = this.view.getSelectedNodes();
1894 var cselitem = false;
1896 var ix = this.view.indexOf(csel[0]);
1897 cselitem = this.store.getAt(ix);
1898 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1904 this.store.each(function(v) {
1906 // start at existing selection.
1907 if (cselitem.id == v.id) {
1913 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1914 match = this.store.indexOf(v);
1920 if (match === false) {
1921 return true; // no more action?
1924 this.view.select(match);
1925 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1926 sn.scrollIntoView(sn.dom.parentNode, false);
1929 onViewScroll : function(e, t){
1931 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){
1935 this.hasQuery = true;
1937 this.loading = this.list.select('.loading', true).first();
1939 if(this.loading === null){
1940 this.list.createChild({
1942 cls: 'loading roo-select2-more-results roo-select2-active',
1943 html: 'Loading more results...'
1946 this.loading = this.list.select('.loading', true).first();
1948 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1950 this.loading.hide();
1953 this.loading.show();
1958 this.loadNext = true;
1960 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1965 addItem : function(o)
1967 var dv = ''; // display value
1969 if (this.displayField) {
1970 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1972 // this is an error condition!!!
1973 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1980 var choice = this.choices.createChild({
1982 cls: 'roo-select2-search-choice',
1991 cls: 'roo-select2-search-choice-close fa fa-times',
1996 }, this.searchField);
1998 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2000 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2008 this.inputEl().dom.value = '';
2013 onRemoveItem : function(e, _self, o)
2017 this.lastItem = Roo.apply([], this.item);
2019 var index = this.item.indexOf(o.data) * 1;
2022 Roo.log('not this item?!');
2026 this.item.splice(index, 1);
2031 this.fireEvent('remove', this, e);
2037 syncValue : function()
2039 if(!this.item.length){
2046 Roo.each(this.item, function(i){
2047 if(_this.valueField){
2048 value.push(i[_this.valueField]);
2055 this.value = value.join(',');
2057 if(this.hiddenField){
2058 this.hiddenField.dom.value = this.value;
2061 this.store.fireEvent("datachanged", this.store);
2066 clearItem : function()
2074 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2082 if(this.tickable && !Roo.isTouch){
2083 this.view.refresh();
2087 inputEl: function ()
2089 if(Roo.isIOS && this.useNativeIOS){
2090 return this.el.select('select.roo-ios-select', true).first();
2093 if(Roo.isTouch && this.mobileTouchView){
2094 return this.el.select('input.form-control',true).first();
2098 return this.searchField;
2101 return this.el.select('input.form-control',true).first();
2104 onTickableFooterButtonClick : function(e, btn, el)
2108 this.lastItem = Roo.apply([], this.item);
2110 if(btn && btn.name == 'cancel'){
2111 this.tickItems = Roo.apply([], this.item);
2120 Roo.each(this.tickItems, function(o){
2128 validate : function()
2130 var v = this.getRawValue();
2133 v = this.getValue();
2136 if(this.disabled || this.allowBlank || v.length){
2145 tickableInputEl : function()
2147 if(!this.tickable || !this.editable){
2148 return this.inputEl();
2151 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2155 getAutoCreateTouchView : function()
2160 cls: 'form-group' //input-group
2166 type : this.inputType,
2167 cls : 'form-control x-combo-noedit',
2168 autocomplete: 'new-password',
2169 placeholder : this.placeholder || '',
2174 input.name = this.name;
2178 input.cls += ' input-' + this.size;
2181 if (this.disabled) {
2182 input.disabled = true;
2193 inputblock.cls += ' input-group';
2195 inputblock.cn.unshift({
2197 cls : 'input-group-addon',
2202 if(this.removable && !this.multiple){
2203 inputblock.cls += ' roo-removable';
2205 inputblock.cn.push({
2208 cls : 'roo-combo-removable-btn close'
2212 if(this.hasFeedback && !this.allowBlank){
2214 inputblock.cls += ' has-feedback';
2216 inputblock.cn.push({
2218 cls: 'glyphicon form-control-feedback'
2225 inputblock.cls += (this.before) ? '' : ' input-group';
2227 inputblock.cn.push({
2229 cls : 'input-group-addon',
2240 cls: 'form-hidden-field'
2254 cls: 'form-hidden-field'
2258 cls: 'roo-select2-choices',
2262 cls: 'roo-select2-search-field',
2275 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2281 if(!this.multiple && this.showToggleBtn){
2288 if (this.caret != false) {
2291 cls: 'fa fa-' + this.caret
2298 cls : 'input-group-addon btn dropdown-toggle',
2303 cls: 'combobox-clear',
2317 combobox.cls += ' roo-select2-container-multi';
2320 var align = this.labelAlign || this.parentLabelAlign();
2322 if (align ==='left' && this.fieldLabel.length) {
2327 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2328 tooltip : 'This field is required'
2332 cls : 'control-label',
2333 html : this.fieldLabel
2344 var labelCfg = cfg.cn[1];
2345 var contentCfg = cfg.cn[2];
2348 if(this.indicatorpos == 'right'){
2352 cls : 'control-label',
2353 html : this.fieldLabel,
2357 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2358 tooltip : 'This field is required'
2371 labelCfg = cfg.cn[0];
2372 contentCfg = cfg.cn[2];
2374 if(this.labelWidth > 12){
2375 labelCfg.style = "width: " + this.labelWidth + 'px';
2378 if(this.labelWidth < 13 && this.labelmd == 0){
2379 this.labelmd = this.labelWidth;
2382 if(this.labellg > 0){
2383 labelCfg.cls += ' col-lg-' + this.labellg;
2384 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2387 if(this.labelmd > 0){
2388 labelCfg.cls += ' col-md-' + this.labelmd;
2389 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2392 if(this.labelsm > 0){
2393 labelCfg.cls += ' col-sm-' + this.labelsm;
2394 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2397 if(this.labelxs > 0){
2398 labelCfg.cls += ' col-xs-' + this.labelxs;
2399 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2403 } else if ( this.fieldLabel.length) {
2407 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2408 tooltip : 'This field is required'
2412 cls : 'control-label',
2413 html : this.fieldLabel
2424 if(this.indicatorpos == 'right'){
2428 cls : 'control-label',
2429 html : this.fieldLabel,
2433 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2434 tooltip : 'This field is required'
2451 var settings = this;
2453 ['xs','sm','md','lg'].map(function(size){
2454 if (settings[size]) {
2455 cfg.cls += ' col-' + size + '-' + settings[size];
2462 initTouchView : function()
2464 this.renderTouchView();
2466 this.touchViewEl.on('scroll', function(){
2467 this.el.dom.scrollTop = 0;
2470 this.originalValue = this.getValue();
2472 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2474 this.inputEl().on("click", this.showTouchView, this);
2475 if (this.triggerEl) {
2476 this.triggerEl.on("click", this.showTouchView, this);
2480 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2481 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2483 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2485 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2486 this.store.on('load', this.onTouchViewLoad, this);
2487 this.store.on('loadexception', this.onTouchViewLoadException, this);
2489 if(this.hiddenName){
2491 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2493 this.hiddenField.dom.value =
2494 this.hiddenValue !== undefined ? this.hiddenValue :
2495 this.value !== undefined ? this.value : '';
2497 this.el.dom.removeAttribute('name');
2498 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2502 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2503 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2506 if(this.removable && !this.multiple){
2507 var close = this.closeTriggerEl();
2509 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2510 close.on('click', this.removeBtnClick, this, close);
2514 * fix the bug in Safari iOS8
2516 this.inputEl().on("focus", function(e){
2517 document.activeElement.blur();
2525 renderTouchView : function()
2527 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2528 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2530 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2531 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2533 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2534 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2535 this.touchViewBodyEl.setStyle('overflow', 'auto');
2537 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2538 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2540 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2541 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2545 showTouchView : function()
2551 this.touchViewHeaderEl.hide();
2553 if(this.modalTitle.length){
2554 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2555 this.touchViewHeaderEl.show();
2558 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2559 this.touchViewEl.show();
2561 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2562 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2563 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2565 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2567 if(this.modalTitle.length){
2568 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2571 this.touchViewBodyEl.setHeight(bodyHeight);
2575 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2577 this.touchViewEl.addClass('in');
2580 this.doTouchViewQuery();
2584 hideTouchView : function()
2586 this.touchViewEl.removeClass('in');
2590 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2592 this.touchViewEl.setStyle('display', 'none');
2597 setTouchViewValue : function()
2604 Roo.each(this.tickItems, function(o){
2609 this.hideTouchView();
2612 doTouchViewQuery : function()
2621 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2625 if(!this.alwaysQuery || this.mode == 'local'){
2626 this.onTouchViewLoad();
2633 onTouchViewBeforeLoad : function(combo,opts)
2639 onTouchViewLoad : function()
2641 if(this.store.getCount() < 1){
2642 this.onTouchViewEmptyResults();
2646 this.clearTouchView();
2648 var rawValue = this.getRawValue();
2650 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2652 this.tickItems = [];
2654 this.store.data.each(function(d, rowIndex){
2655 var row = this.touchViewListGroup.createChild(template);
2657 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2658 row.addClass(d.data.cls);
2661 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2664 html : d.data[this.displayField]
2667 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2668 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2671 row.removeClass('selected');
2672 if(!this.multiple && this.valueField &&
2673 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2676 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2677 row.addClass('selected');
2680 if(this.multiple && this.valueField &&
2681 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2685 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2686 this.tickItems.push(d.data);
2689 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2693 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2695 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2697 if(this.modalTitle.length){
2698 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2701 var listHeight = this.touchViewListGroup.getHeight();
2705 if(firstChecked && listHeight > bodyHeight){
2706 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2711 onTouchViewLoadException : function()
2713 this.hideTouchView();
2716 onTouchViewEmptyResults : function()
2718 this.clearTouchView();
2720 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2722 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2726 clearTouchView : function()
2728 this.touchViewListGroup.dom.innerHTML = '';
2731 onTouchViewClick : function(e, el, o)
2736 var rowIndex = o.rowIndex;
2738 var r = this.store.getAt(rowIndex);
2740 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2743 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2744 c.dom.removeAttribute('checked');
2747 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2749 this.setFromData(r.data);
2751 var close = this.closeTriggerEl();
2757 this.hideTouchView();
2759 this.fireEvent('select', this, r, rowIndex);
2764 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2765 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2766 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2770 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2771 this.addItem(r.data);
2772 this.tickItems.push(r.data);
2776 getAutoCreateNativeIOS : function()
2779 cls: 'form-group' //input-group,
2784 cls : 'roo-ios-select'
2788 combobox.name = this.name;
2791 if (this.disabled) {
2792 combobox.disabled = true;
2795 var settings = this;
2797 ['xs','sm','md','lg'].map(function(size){
2798 if (settings[size]) {
2799 cfg.cls += ' col-' + size + '-' + settings[size];
2809 initIOSView : function()
2811 this.store.on('load', this.onIOSViewLoad, this);
2816 onIOSViewLoad : function()
2818 if(this.store.getCount() < 1){
2822 this.clearIOSView();
2824 if(this.allowBlank) {
2826 var default_text = '-- SELECT --';
2828 var opt = this.inputEl().createChild({
2835 o[this.valueField] = 0;
2836 o[this.displayField] = default_text;
2838 this.ios_options.push({
2845 this.store.data.each(function(d, rowIndex){
2849 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2850 html = d.data[this.displayField];
2855 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2856 value = d.data[this.valueField];
2865 if(this.value == d.data[this.valueField]){
2866 option['selected'] = true;
2869 var opt = this.inputEl().createChild(option);
2871 this.ios_options.push({
2878 this.inputEl().on('change', function(){
2879 this.fireEvent('select', this);
2884 clearIOSView: function()
2886 this.inputEl().dom.innerHTML = '';
2888 this.ios_options = [];
2891 setIOSValue: function(v)
2895 if(!this.ios_options){
2899 Roo.each(this.ios_options, function(opts){
2901 opts.el.dom.removeAttribute('selected');
2903 if(opts.data[this.valueField] != v){
2907 opts.el.dom.setAttribute('selected', true);
2913 * @cfg {Boolean} grow
2917 * @cfg {Number} growMin
2921 * @cfg {Number} growMax
2930 Roo.apply(Roo.bootstrap.ComboBox, {
2934 cls: 'modal-header',
2956 cls: 'list-group-item',
2960 cls: 'roo-combobox-list-group-item-value'
2964 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2978 listItemCheckbox : {
2980 cls: 'list-group-item',
2984 cls: 'roo-combobox-list-group-item-value'
2988 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3004 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3009 cls: 'modal-footer',
3017 cls: 'col-xs-6 text-left',
3020 cls: 'btn btn-danger roo-touch-view-cancel',
3026 cls: 'col-xs-6 text-right',
3029 cls: 'btn btn-success roo-touch-view-ok',
3040 Roo.apply(Roo.bootstrap.ComboBox, {
3042 touchViewTemplate : {
3044 cls: 'modal fade roo-combobox-touch-view',
3048 cls: 'modal-dialog',
3049 style : 'position:fixed', // we have to fix position....
3053 cls: 'modal-content',
3055 Roo.bootstrap.ComboBox.header,
3056 Roo.bootstrap.ComboBox.body,
3057 Roo.bootstrap.ComboBox.footer