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 default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
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 DEPRICATED - uses BS4 is-valid now
300 invalidClass : "has-warning",
303 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
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,
323 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
325 mobile_restrict_height : false,
339 btnPosition : 'right',
341 showToggleBtn : true,
343 emptyResultText: 'Empty',
344 triggerText : 'Select',
347 // element that contains real text value.. (when hidden is used..)
349 getAutoCreate : function()
354 * Render classic select for iso
357 if(Roo.isIOS && this.useNativeIOS){
358 cfg = this.getAutoCreateNativeIOS();
366 if(Roo.isTouch && this.mobileTouchView){
367 cfg = this.getAutoCreateTouchView();
375 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
380 * ComboBox with tickable selections
383 var align = this.labelAlign || this.parentLabelAlign();
386 cls : 'form-group roo-combobox-tickable' //input-group
389 var btn_text_select = '';
390 var btn_text_done = '';
391 var btn_text_cancel = '';
393 if (this.btn_text_show) {
394 btn_text_select = 'Select';
395 btn_text_done = 'Done';
396 btn_text_cancel = 'Cancel';
401 cls : 'tickable-buttons',
406 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
407 //html : this.triggerText
408 html: btn_text_select
414 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
422 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
424 html: btn_text_cancel
432 cls: 'roo-select2-search-field-input'
438 Roo.each(buttons.cn, function(c){
440 c.cls += ' btn-' + _this.size;
443 if (_this.disabled) {
450 style : 'display: contents',
455 cls: 'form-hidden-field'
459 cls: 'roo-select2-choices',
463 cls: 'roo-select2-search-field',
474 cls: 'roo-select2-container input-group roo-select2-container-multi',
480 // cls: 'typeahead typeahead-long dropdown-menu',
481 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
486 if(this.hasFeedback && !this.allowBlank){
490 cls: 'glyphicon form-control-feedback'
493 combobox.cn.push(feedback);
500 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
501 tooltip : 'This field is required'
503 if (Roo.bootstrap.version == 4) {
506 style : 'display:none'
509 if (align ==='left' && this.fieldLabel.length) {
511 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
518 cls : 'control-label col-form-label',
519 html : this.fieldLabel
531 var labelCfg = cfg.cn[1];
532 var contentCfg = cfg.cn[2];
535 if(this.indicatorpos == 'right'){
541 cls : 'control-label col-form-label',
545 html : this.fieldLabel
561 labelCfg = cfg.cn[0];
562 contentCfg = cfg.cn[1];
566 if(this.labelWidth > 12){
567 labelCfg.style = "width: " + this.labelWidth + 'px';
570 if(this.labelWidth < 13 && this.labelmd == 0){
571 this.labelmd = this.labelWidth;
574 if(this.labellg > 0){
575 labelCfg.cls += ' col-lg-' + this.labellg;
576 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
579 if(this.labelmd > 0){
580 labelCfg.cls += ' col-md-' + this.labelmd;
581 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
584 if(this.labelsm > 0){
585 labelCfg.cls += ' col-sm-' + this.labelsm;
586 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
589 if(this.labelxs > 0){
590 labelCfg.cls += ' col-xs-' + this.labelxs;
591 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
595 } else if ( this.fieldLabel.length) {
596 // Roo.log(" label");
601 //cls : 'input-group-addon',
602 html : this.fieldLabel
607 if(this.indicatorpos == 'right'){
611 //cls : 'input-group-addon',
612 html : this.fieldLabel
622 // Roo.log(" no label && no align");
629 ['xs','sm','md','lg'].map(function(size){
630 if (settings[size]) {
631 cfg.cls += ' col-' + size + '-' + settings[size];
639 _initEventsCalled : false,
642 initEvents: function()
644 if (this._initEventsCalled) { // as we call render... prevent looping...
647 this._initEventsCalled = true;
650 throw "can not find store for combo";
653 this.indicator = this.indicatorEl();
655 this.store = Roo.factory(this.store, Roo.data);
656 this.store.parent = this;
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) {
662 // remove this element....
663 var e = this.el.dom, k=0;
664 while (e ) { e = e.previousSibling; ++k;}
669 this.rendered = false;
671 this.render(this.parent().getChildContainer(true), k);
674 if(Roo.isIOS && this.useNativeIOS){
683 if(Roo.isTouch && this.mobileTouchView){
684 this.initTouchView();
689 this.initTickableEvents();
693 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
697 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
699 this.hiddenField.dom.value =
700 this.hiddenValue !== undefined ? this.hiddenValue :
701 this.value !== undefined ? this.value : '';
703 // prevent input submission
704 this.el.dom.removeAttribute('name');
705 this.hiddenField.dom.setAttribute('name', this.hiddenName);
710 // this.el.dom.setAttribute('autocomplete', 'off');
713 var cls = 'x-combo-list';
715 //this.list = new Roo.Layer({
716 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
722 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
723 _this.list.setWidth(lw);
726 this.list.on('mouseover', this.onViewOver, this);
727 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 = Roo.bootstrap.version == 4 ?
776 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
777 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
780 this.view = new Roo.View(this.list, this.tpl, {
781 singleSelect:true, store: this.store, selectedClass: this.selectedClass
783 //this.view.wrapEl.setDisplayed(false);
784 this.view.on('click', this.onViewClick, this);
787 this.store.on('beforeload', this.onBeforeLoad, this);
788 this.store.on('load', this.onLoad, this);
789 this.store.on('loadexception', this.onLoadException, this);
792 this.resizer = new Roo.Resizable(this.list, {
793 pinned:true, handles:'se'
795 this.resizer.on('resize', function(r, w, h){
796 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
798 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
799 this.restrictHeight();
801 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
805 this.editable = true;
806 this.setEditable(false);
811 if (typeof(this.events.add.listeners) != 'undefined') {
813 this.addicon = this.wrap.createChild(
814 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
816 this.addicon.on('click', function(e) {
817 this.fireEvent('add', this);
820 if (typeof(this.events.edit.listeners) != 'undefined') {
822 this.editicon = this.wrap.createChild(
823 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
825 this.editicon.setStyle('margin-left', '40px');
827 this.editicon.on('click', function(e) {
829 // we fire even if inothing is selected..
830 this.fireEvent('edit', this, this.lastData );
836 this.keyNav = new Roo.KeyNav(this.inputEl(), {
838 this.inKeyMode = true;
842 "down" : function(e){
843 if(!this.isExpanded()){
844 this.onTriggerClick();
846 this.inKeyMode = true;
851 "enter" : function(e){
852 // this.onViewClick();
856 if(this.fireEvent("specialkey", this, e)){
857 this.onViewClick(false);
870 if(this.fireEvent("specialkey", this, e)){
871 this.onViewClick(false);
879 doRelay : function(foo, bar, hname){
880 if(hname == 'down' || this.scope.isExpanded()){
881 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
890 this.queryDelay = Math.max(this.queryDelay || 10,
891 this.mode == 'local' ? 10 : 250);
894 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
897 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
899 if(this.editable !== false){
900 this.inputEl().on("keyup", this.onKeyUp, this);
902 if(this.forceSelection){
903 this.inputEl().on('blur', this.doForce, this);
907 this.choices = this.el.select('ul.roo-select2-choices', true).first();
908 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
912 initTickableEvents: function()
918 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
920 this.hiddenField.dom.value =
921 this.hiddenValue !== undefined ? this.hiddenValue :
922 this.value !== undefined ? this.value : '';
924 // prevent input submission
925 this.el.dom.removeAttribute('name');
926 this.hiddenField.dom.setAttribute('name', this.hiddenName);
931 // this.list = this.el.select('ul.dropdown-menu',true).first();
933 this.choices = this.el.select('ul.roo-select2-choices', true).first();
934 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
935 if(this.triggerList){
936 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
939 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
940 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
942 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
943 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
945 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
946 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
948 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
949 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
950 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
953 this.cancelBtn.hide();
958 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
959 _this.list.setWidth(lw);
962 this.list.on('mouseover', this.onViewOver, this);
963 this.list.on('mousemove', this.onViewMove, this);
965 this.list.on('scroll', this.onViewScroll, this);
968 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
969 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
972 this.view = new Roo.View(this.list, this.tpl, {
977 selectedClass: this.selectedClass
980 //this.view.wrapEl.setDisplayed(false);
981 this.view.on('click', this.onViewClick, this);
985 this.store.on('beforeload', this.onBeforeLoad, this);
986 this.store.on('load', this.onLoad, this);
987 this.store.on('loadexception', this.onLoadException, this);
990 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
992 this.inKeyMode = true;
996 "down" : function(e){
997 this.inKeyMode = true;
1001 "enter" : function(e){
1002 if(this.fireEvent("specialkey", this, e)){
1003 this.onViewClick(false);
1009 "esc" : function(e){
1010 this.onTickableFooterButtonClick(e, false, false);
1013 "tab" : function(e){
1014 this.fireEvent("specialkey", this, e);
1016 this.onTickableFooterButtonClick(e, false, false);
1023 doRelay : function(e, fn, key){
1024 if(this.scope.isExpanded()){
1025 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1034 this.queryDelay = Math.max(this.queryDelay || 10,
1035 this.mode == 'local' ? 10 : 250);
1038 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1041 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1044 if(this.editable !== false){
1045 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1048 this.indicator = this.indicatorEl();
1051 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1052 this.indicator.hide();
1057 onDestroy : function(){
1059 this.view.setStore(null);
1060 this.view.el.removeAllListeners();
1061 this.view.el.remove();
1062 this.view.purgeListeners();
1065 this.list.dom.innerHTML = '';
1069 this.store.un('beforeload', this.onBeforeLoad, this);
1070 this.store.un('load', this.onLoad, this);
1071 this.store.un('loadexception', this.onLoadException, this);
1073 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1077 fireKey : function(e){
1078 if(e.isNavKeyPress() && !this.list.isVisible()){
1079 this.fireEvent("specialkey", this, e);
1084 onResize: function(w, h){
1085 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1087 // if(typeof w != 'number'){
1088 // // we do not handle it!?!?
1091 // var tw = this.trigger.getWidth();
1092 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1093 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1095 // this.inputEl().setWidth( this.adjustWidth('input', x));
1097 // //this.trigger.setStyle('left', x+'px');
1099 // if(this.list && this.listWidth === undefined){
1100 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1101 // this.list.setWidth(lw);
1102 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1110 * Allow or prevent the user from directly editing the field text. If false is passed,
1111 * the user will only be able to select from the items defined in the dropdown list. This method
1112 * is the runtime equivalent of setting the 'editable' config option at config time.
1113 * @param {Boolean} value True to allow the user to directly edit the field text
1115 setEditable : function(value){
1116 if(value == this.editable){
1119 this.editable = value;
1121 this.inputEl().dom.setAttribute('readOnly', true);
1122 this.inputEl().on('mousedown', this.onTriggerClick, this);
1123 this.inputEl().addClass('x-combo-noedit');
1125 this.inputEl().dom.setAttribute('readOnly', false);
1126 this.inputEl().un('mousedown', this.onTriggerClick, this);
1127 this.inputEl().removeClass('x-combo-noedit');
1133 onBeforeLoad : function(combo,opts){
1138 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1140 this.restrictHeight();
1141 this.selectedIndex = -1;
1145 onLoad : function(){
1147 this.hasQuery = false;
1153 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1154 this.loading.hide();
1157 if(this.store.getCount() > 0){
1160 this.restrictHeight();
1161 if(this.lastQuery == this.allQuery){
1162 if(this.editable && !this.tickable){
1163 this.inputEl().dom.select();
1167 !this.selectByValue(this.value, true) &&
1170 !this.store.lastOptions ||
1171 typeof(this.store.lastOptions.add) == 'undefined' ||
1172 this.store.lastOptions.add != true
1175 this.select(0, true);
1181 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1182 this.taTask.delay(this.typeAheadDelay);
1186 this.onEmptyResults();
1192 onLoadException : function()
1194 this.hasQuery = false;
1196 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1197 this.loading.hide();
1200 if(this.tickable && this.editable){
1205 // only causes errors at present
1206 //Roo.log(this.store.reader.jsonData);
1207 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1209 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1215 onTypeAhead : function(){
1216 if(this.store.getCount() > 0){
1217 var r = this.store.getAt(0);
1218 var newValue = r.data[this.displayField];
1219 var len = newValue.length;
1220 var selStart = this.getRawValue().length;
1222 if(selStart != len){
1223 this.setRawValue(newValue);
1224 this.selectText(selStart, newValue.length);
1230 onSelect : function(record, index){
1232 if(this.fireEvent('beforeselect', this, record, index) !== false){
1234 this.setFromData(index > -1 ? record.data : false);
1237 this.fireEvent('select', this, record, index);
1242 * Returns the currently selected field value or empty string if no value is set.
1243 * @return {String} value The selected value
1245 getValue : function()
1247 if(Roo.isIOS && this.useNativeIOS){
1248 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1252 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1255 if(this.valueField){
1256 return typeof this.value != 'undefined' ? this.value : '';
1258 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1262 getRawValue : function()
1264 if(Roo.isIOS && this.useNativeIOS){
1265 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1268 var v = this.inputEl().getValue();
1274 * Clears any text/value currently set in the field
1276 clearValue : function(){
1278 if(this.hiddenField){
1279 this.hiddenField.dom.value = '';
1282 this.setRawValue('');
1283 this.lastSelectionText = '';
1284 this.lastData = false;
1286 var close = this.closeTriggerEl();
1297 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1298 * will be displayed in the field. If the value does not match the data value of an existing item,
1299 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1300 * Otherwise the field will be blank (although the value will still be set).
1301 * @param {String} value The value to match
1303 setValue : function(v)
1305 if(Roo.isIOS && this.useNativeIOS){
1306 this.setIOSValue(v);
1316 if(this.valueField){
1317 var r = this.findRecord(this.valueField, v);
1319 text = r.data[this.displayField];
1320 }else if(this.valueNotFoundText !== undefined){
1321 text = this.valueNotFoundText;
1324 this.lastSelectionText = text;
1325 if(this.hiddenField){
1326 this.hiddenField.dom.value = v;
1328 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1331 var close = this.closeTriggerEl();
1334 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1340 * @property {Object} the last set data for the element
1345 * Sets the value of the field based on a object which is related to the record format for the store.
1346 * @param {Object} value the value to set as. or false on reset?
1348 setFromData : function(o){
1355 var dv = ''; // display value
1356 var vv = ''; // value value..
1358 if (this.displayField) {
1359 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1361 // this is an error condition!!!
1362 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1365 if(this.valueField){
1366 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1369 var close = this.closeTriggerEl();
1372 if(dv.length || vv * 1 > 0){
1374 this.blockFocus=true;
1380 if(this.hiddenField){
1381 this.hiddenField.dom.value = vv;
1383 this.lastSelectionText = dv;
1384 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1388 // no hidden field.. - we store the value in 'value', but still display
1389 // display field!!!!
1390 this.lastSelectionText = dv;
1391 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1399 // overridden so that last data is reset..
1406 this.setValue(this.originalValue);
1407 //this.clearInvalid();
1408 this.lastData = false;
1410 this.view.clearSelections();
1416 findRecord : function(prop, value){
1418 if(this.store.getCount() > 0){
1419 this.store.each(function(r){
1420 if(r.data[prop] == value){
1432 // returns hidden if it's set..
1433 if (!this.rendered) {return ''};
1434 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1438 onViewMove : function(e, t){
1439 this.inKeyMode = false;
1443 onViewOver : function(e, t){
1444 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1447 var item = this.view.findItemFromChild(t);
1450 var index = this.view.indexOf(item);
1451 this.select(index, false);
1456 onViewClick : function(view, doFocus, el, e)
1458 var index = this.view.getSelectedIndexes()[0];
1460 var r = this.store.getAt(index);
1464 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1471 Roo.each(this.tickItems, function(v,k){
1473 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1475 _this.tickItems.splice(k, 1);
1477 if(typeof(e) == 'undefined' && view == false){
1478 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1490 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1491 this.tickItems.push(r.data);
1494 if(typeof(e) == 'undefined' && view == false){
1495 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1502 this.onSelect(r, index);
1504 if(doFocus !== false && !this.blockFocus){
1505 this.inputEl().focus();
1510 restrictHeight : function(){
1511 //this.innerList.dom.style.height = '';
1512 //var inner = this.innerList.dom;
1513 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1514 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1515 //this.list.beginUpdate();
1516 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1517 this.list.alignTo(this.inputEl(), this.listAlign);
1518 this.list.alignTo(this.inputEl(), this.listAlign);
1519 //this.list.endUpdate();
1523 onEmptyResults : function(){
1525 if(this.tickable && this.editable){
1526 this.hasFocus = false;
1527 this.restrictHeight();
1535 * Returns true if the dropdown list is expanded, else false.
1537 isExpanded : function(){
1538 return this.list.isVisible();
1542 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1543 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1544 * @param {String} value The data value of the item to select
1545 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1546 * selected item if it is not currently in view (defaults to true)
1547 * @return {Boolean} True if the value matched an item in the list, else false
1549 selectByValue : function(v, scrollIntoView){
1550 if(v !== undefined && v !== null){
1551 var r = this.findRecord(this.valueField || this.displayField, v);
1553 this.select(this.store.indexOf(r), scrollIntoView);
1561 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1562 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1563 * @param {Number} index The zero-based index of the list item to select
1564 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1565 * selected item if it is not currently in view (defaults to true)
1567 select : function(index, scrollIntoView){
1568 this.selectedIndex = index;
1569 this.view.select(index);
1570 if(scrollIntoView !== false){
1571 var el = this.view.getNode(index);
1573 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1576 this.list.scrollChildIntoView(el, false);
1582 selectNext : function(){
1583 var ct = this.store.getCount();
1585 if(this.selectedIndex == -1){
1587 }else if(this.selectedIndex < ct-1){
1588 this.select(this.selectedIndex+1);
1594 selectPrev : function(){
1595 var ct = this.store.getCount();
1597 if(this.selectedIndex == -1){
1599 }else if(this.selectedIndex != 0){
1600 this.select(this.selectedIndex-1);
1606 onKeyUp : function(e){
1607 if(this.editable !== false && !e.isSpecialKey()){
1608 this.lastKey = e.getKey();
1609 this.dqTask.delay(this.queryDelay);
1614 validateBlur : function(){
1615 return !this.list || !this.list.isVisible();
1619 initQuery : function(){
1621 var v = this.getRawValue();
1623 if(this.tickable && this.editable){
1624 v = this.tickableInputEl().getValue();
1631 doForce : function(){
1632 if(this.inputEl().dom.value.length > 0){
1633 this.inputEl().dom.value =
1634 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1640 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1641 * query allowing the query action to be canceled if needed.
1642 * @param {String} query The SQL query to execute
1643 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1644 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1645 * saved in the current store (defaults to false)
1647 doQuery : function(q, forceAll){
1649 if(q === undefined || q === null){
1658 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1663 forceAll = qe.forceAll;
1664 if(forceAll === true || (q.length >= this.minChars)){
1666 this.hasQuery = true;
1668 if(this.lastQuery != q || this.alwaysQuery){
1670 if(this.mode == 'local'){
1671 this.selectedIndex = -1;
1673 this.store.clearFilter();
1676 if(this.specialFilter){
1677 this.fireEvent('specialfilter', this);
1682 this.store.filter(this.displayField, q);
1685 this.store.fireEvent("datachanged", this.store);
1692 this.store.baseParams[this.queryParam] = q;
1694 var options = {params : this.getParams(q)};
1698 options.params.start = this.page * this.pageSize;
1701 this.store.load(options);
1704 * this code will make the page width larger, at the beginning, the list not align correctly,
1705 * we should expand the list on onLoad
1711 this.selectedIndex = -1;
1716 this.loadNext = false;
1720 getParams : function(q){
1722 //p[this.queryParam] = q;
1726 p.limit = this.pageSize;
1732 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1734 collapse : function(){
1735 if(!this.isExpanded()){
1741 this.hasFocus = false;
1745 this.cancelBtn.hide();
1746 this.trigger.show();
1749 this.tickableInputEl().dom.value = '';
1750 this.tickableInputEl().blur();
1755 Roo.get(document).un('mousedown', this.collapseIf, this);
1756 Roo.get(document).un('mousewheel', this.collapseIf, this);
1757 if (!this.editable) {
1758 Roo.get(document).un('keydown', this.listKeyPress, this);
1760 this.fireEvent('collapse', this);
1766 collapseIf : function(e){
1767 var in_combo = e.within(this.el);
1768 var in_list = e.within(this.list);
1769 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1771 if (in_combo || in_list || is_list) {
1772 //e.stopPropagation();
1777 this.onTickableFooterButtonClick(e, false, false);
1785 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1787 expand : function(){
1789 if(this.isExpanded() || !this.hasFocus){
1793 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1794 this.list.setWidth(lw);
1800 this.restrictHeight();
1804 this.tickItems = Roo.apply([], this.item);
1807 this.cancelBtn.show();
1808 this.trigger.hide();
1811 this.tickableInputEl().focus();
1816 Roo.get(document).on('mousedown', this.collapseIf, this);
1817 Roo.get(document).on('mousewheel', this.collapseIf, this);
1818 if (!this.editable) {
1819 Roo.get(document).on('keydown', this.listKeyPress, this);
1822 this.fireEvent('expand', this);
1826 // Implements the default empty TriggerField.onTriggerClick function
1827 onTriggerClick : function(e)
1829 Roo.log('trigger click');
1831 if(this.disabled || !this.triggerList){
1836 this.loadNext = false;
1838 if(this.isExpanded()){
1840 if (!this.blockFocus) {
1841 this.inputEl().focus();
1845 this.hasFocus = true;
1846 if(this.triggerAction == 'all') {
1847 this.doQuery(this.allQuery, true);
1849 this.doQuery(this.getRawValue());
1851 if (!this.blockFocus) {
1852 this.inputEl().focus();
1857 onTickableTriggerClick : function(e)
1864 this.loadNext = false;
1865 this.hasFocus = true;
1867 if(this.triggerAction == 'all') {
1868 this.doQuery(this.allQuery, true);
1870 this.doQuery(this.getRawValue());
1874 onSearchFieldClick : function(e)
1876 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1877 this.onTickableFooterButtonClick(e, false, false);
1881 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1886 this.loadNext = false;
1887 this.hasFocus = true;
1889 if(this.triggerAction == 'all') {
1890 this.doQuery(this.allQuery, true);
1892 this.doQuery(this.getRawValue());
1896 listKeyPress : function(e)
1898 //Roo.log('listkeypress');
1899 // scroll to first matching element based on key pres..
1900 if (e.isSpecialKey()) {
1903 var k = String.fromCharCode(e.getKey()).toUpperCase();
1906 var csel = this.view.getSelectedNodes();
1907 var cselitem = false;
1909 var ix = this.view.indexOf(csel[0]);
1910 cselitem = this.store.getAt(ix);
1911 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1917 this.store.each(function(v) {
1919 // start at existing selection.
1920 if (cselitem.id == v.id) {
1926 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1927 match = this.store.indexOf(v);
1933 if (match === false) {
1934 return true; // no more action?
1937 this.view.select(match);
1938 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1939 sn.scrollIntoView(sn.dom.parentNode, false);
1942 onViewScroll : function(e, t){
1944 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){
1948 this.hasQuery = true;
1950 this.loading = this.list.select('.loading', true).first();
1952 if(this.loading === null){
1953 this.list.createChild({
1955 cls: 'loading roo-select2-more-results roo-select2-active',
1956 html: 'Loading more results...'
1959 this.loading = this.list.select('.loading', true).first();
1961 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1963 this.loading.hide();
1966 this.loading.show();
1971 this.loadNext = true;
1973 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1978 addItem : function(o)
1980 var dv = ''; // display value
1982 if (this.displayField) {
1983 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1985 // this is an error condition!!!
1986 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1993 var choice = this.choices.createChild({
1995 cls: 'roo-select2-search-choice',
2004 cls: 'roo-select2-search-choice-close fa fa-times',
2009 }, this.searchField);
2011 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2013 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2021 this.inputEl().dom.value = '';
2026 onRemoveItem : function(e, _self, o)
2030 this.lastItem = Roo.apply([], this.item);
2032 var index = this.item.indexOf(o.data) * 1;
2035 Roo.log('not this item?!');
2039 this.item.splice(index, 1);
2044 this.fireEvent('remove', this, e);
2050 syncValue : function()
2052 if(!this.item.length){
2059 Roo.each(this.item, function(i){
2060 if(_this.valueField){
2061 value.push(i[_this.valueField]);
2068 this.value = value.join(',');
2070 if(this.hiddenField){
2071 this.hiddenField.dom.value = this.value;
2074 this.store.fireEvent("datachanged", this.store);
2079 clearItem : function()
2087 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2095 if(this.tickable && !Roo.isTouch){
2096 this.view.refresh();
2100 inputEl: function ()
2102 if(Roo.isIOS && this.useNativeIOS){
2103 return this.el.select('select.roo-ios-select', true).first();
2106 if(Roo.isTouch && this.mobileTouchView){
2107 return this.el.select('input.form-control',true).first();
2111 return this.searchField;
2114 return this.el.select('input.form-control',true).first();
2117 onTickableFooterButtonClick : function(e, btn, el)
2121 this.lastItem = Roo.apply([], this.item);
2123 if(btn && btn.name == 'cancel'){
2124 this.tickItems = Roo.apply([], this.item);
2133 Roo.each(this.tickItems, function(o){
2141 validate : function()
2143 if(this.getVisibilityEl().hasClass('hidden')){
2147 var v = this.getRawValue();
2150 v = this.getValue();
2153 if(this.disabled || this.allowBlank || v.length){
2162 tickableInputEl : function()
2164 if(!this.tickable || !this.editable){
2165 return this.inputEl();
2168 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2172 getAutoCreateTouchView : function()
2177 cls: 'form-group' //input-group
2183 type : this.inputType,
2184 cls : 'form-control x-combo-noedit',
2185 autocomplete: 'new-password',
2186 placeholder : this.placeholder || '',
2191 input.name = this.name;
2195 input.cls += ' input-' + this.size;
2198 if (this.disabled) {
2199 input.disabled = true;
2210 inputblock.cls += ' input-group';
2212 inputblock.cn.unshift({
2214 cls : 'input-group-addon input-group-prepend input-group-text',
2219 if(this.removable && !this.multiple){
2220 inputblock.cls += ' roo-removable';
2222 inputblock.cn.push({
2225 cls : 'roo-combo-removable-btn close'
2229 if(this.hasFeedback && !this.allowBlank){
2231 inputblock.cls += ' has-feedback';
2233 inputblock.cn.push({
2235 cls: 'glyphicon form-control-feedback'
2242 inputblock.cls += (this.before) ? '' : ' input-group';
2244 inputblock.cn.push({
2246 cls : 'input-group-addon input-group-append input-group-text',
2252 var ibwrap = inputblock;
2257 cls: 'roo-select2-choices',
2261 cls: 'roo-select2-search-field',
2274 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2279 cls: 'form-hidden-field'
2285 if(!this.multiple && this.showToggleBtn){
2291 if (this.caret != false) {
2294 cls: 'fa fa-' + this.caret
2301 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2303 Roo.bootstrap.version == 3 ? caret : '',
2306 cls: 'combobox-clear',
2320 combobox.cls += ' roo-select2-container-multi';
2323 var align = this.labelAlign || this.parentLabelAlign();
2325 if (align ==='left' && this.fieldLabel.length) {
2330 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2331 tooltip : 'This field is required'
2335 cls : 'control-label col-form-label',
2336 html : this.fieldLabel
2347 var labelCfg = cfg.cn[1];
2348 var contentCfg = cfg.cn[2];
2351 if(this.indicatorpos == 'right'){
2356 cls : 'control-label col-form-label',
2360 html : this.fieldLabel
2364 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2365 tooltip : 'This field is required'
2378 labelCfg = cfg.cn[0];
2379 contentCfg = cfg.cn[1];
2384 if(this.labelWidth > 12){
2385 labelCfg.style = "width: " + this.labelWidth + 'px';
2388 if(this.labelWidth < 13 && this.labelmd == 0){
2389 this.labelmd = this.labelWidth;
2392 if(this.labellg > 0){
2393 labelCfg.cls += ' col-lg-' + this.labellg;
2394 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2397 if(this.labelmd > 0){
2398 labelCfg.cls += ' col-md-' + this.labelmd;
2399 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2402 if(this.labelsm > 0){
2403 labelCfg.cls += ' col-sm-' + this.labelsm;
2404 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2407 if(this.labelxs > 0){
2408 labelCfg.cls += ' col-xs-' + this.labelxs;
2409 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2413 } else if ( this.fieldLabel.length) {
2417 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2418 tooltip : 'This field is required'
2422 cls : 'control-label',
2423 html : this.fieldLabel
2434 if(this.indicatorpos == 'right'){
2438 cls : 'control-label',
2439 html : this.fieldLabel,
2443 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2444 tooltip : 'This field is required'
2461 var settings = this;
2463 ['xs','sm','md','lg'].map(function(size){
2464 if (settings[size]) {
2465 cfg.cls += ' col-' + size + '-' + settings[size];
2472 initTouchView : function()
2474 this.renderTouchView();
2476 this.touchViewEl.on('scroll', function(){
2477 this.el.dom.scrollTop = 0;
2480 this.originalValue = this.getValue();
2482 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2484 this.inputEl().on("click", this.showTouchView, this);
2485 if (this.triggerEl) {
2486 this.triggerEl.on("click", this.showTouchView, this);
2490 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2491 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2493 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2495 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2496 this.store.on('load', this.onTouchViewLoad, this);
2497 this.store.on('loadexception', this.onTouchViewLoadException, this);
2499 if(this.hiddenName){
2501 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2503 this.hiddenField.dom.value =
2504 this.hiddenValue !== undefined ? this.hiddenValue :
2505 this.value !== undefined ? this.value : '';
2507 this.el.dom.removeAttribute('name');
2508 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2512 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2513 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2516 if(this.removable && !this.multiple){
2517 var close = this.closeTriggerEl();
2519 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2520 close.on('click', this.removeBtnClick, this, close);
2524 * fix the bug in Safari iOS8
2526 this.inputEl().on("focus", function(e){
2527 document.activeElement.blur();
2530 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2537 renderTouchView : function()
2539 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2540 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2542 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2543 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2545 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2546 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2547 this.touchViewBodyEl.setStyle('overflow', 'auto');
2549 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2550 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2552 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2553 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2557 showTouchView : function()
2563 this.touchViewHeaderEl.hide();
2565 if(this.modalTitle.length){
2566 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2567 this.touchViewHeaderEl.show();
2570 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2571 this.touchViewEl.show();
2573 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2575 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2576 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2578 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2580 if(this.modalTitle.length){
2581 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2584 this.touchViewBodyEl.setHeight(bodyHeight);
2588 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2590 this.touchViewEl.addClass('in');
2593 if(this._touchViewMask){
2594 Roo.get(document.body).addClass("x-body-masked");
2595 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2596 this._touchViewMask.setStyle('z-index', 10000);
2597 this._touchViewMask.addClass('show');
2600 this.doTouchViewQuery();
2604 hideTouchView : function()
2606 this.touchViewEl.removeClass('in');
2610 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2612 this.touchViewEl.setStyle('display', 'none');
2615 if(this._touchViewMask){
2616 this._touchViewMask.removeClass('show');
2617 Roo.get(document.body).removeClass("x-body-masked");
2621 setTouchViewValue : function()
2628 Roo.each(this.tickItems, function(o){
2633 this.hideTouchView();
2636 doTouchViewQuery : function()
2645 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2649 if(!this.alwaysQuery || this.mode == 'local'){
2650 this.onTouchViewLoad();
2657 onTouchViewBeforeLoad : function(combo,opts)
2663 onTouchViewLoad : function()
2665 if(this.store.getCount() < 1){
2666 this.onTouchViewEmptyResults();
2670 this.clearTouchView();
2672 var rawValue = this.getRawValue();
2674 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2676 this.tickItems = [];
2678 this.store.data.each(function(d, rowIndex){
2679 var row = this.touchViewListGroup.createChild(template);
2681 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2682 row.addClass(d.data.cls);
2685 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2688 html : d.data[this.displayField]
2691 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2692 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2695 row.removeClass('selected');
2696 if(!this.multiple && this.valueField &&
2697 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2700 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2701 row.addClass('selected');
2704 if(this.multiple && this.valueField &&
2705 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2709 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2710 this.tickItems.push(d.data);
2713 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2717 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2719 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2721 if(this.modalTitle.length){
2722 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2725 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2727 if(this.mobile_restrict_height && listHeight < bodyHeight){
2728 this.touchViewBodyEl.setHeight(listHeight);
2733 if(firstChecked && listHeight > bodyHeight){
2734 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2739 onTouchViewLoadException : function()
2741 this.hideTouchView();
2744 onTouchViewEmptyResults : function()
2746 this.clearTouchView();
2748 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2750 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2754 clearTouchView : function()
2756 this.touchViewListGroup.dom.innerHTML = '';
2759 onTouchViewClick : function(e, el, o)
2764 var rowIndex = o.rowIndex;
2766 var r = this.store.getAt(rowIndex);
2768 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2771 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2772 c.dom.removeAttribute('checked');
2775 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2777 this.setFromData(r.data);
2779 var close = this.closeTriggerEl();
2785 this.hideTouchView();
2787 this.fireEvent('select', this, r, rowIndex);
2792 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2793 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2794 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2798 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2799 this.addItem(r.data);
2800 this.tickItems.push(r.data);
2804 getAutoCreateNativeIOS : function()
2807 cls: 'form-group' //input-group,
2812 cls : 'roo-ios-select'
2816 combobox.name = this.name;
2819 if (this.disabled) {
2820 combobox.disabled = true;
2823 var settings = this;
2825 ['xs','sm','md','lg'].map(function(size){
2826 if (settings[size]) {
2827 cfg.cls += ' col-' + size + '-' + settings[size];
2837 initIOSView : function()
2839 this.store.on('load', this.onIOSViewLoad, this);
2844 onIOSViewLoad : function()
2846 if(this.store.getCount() < 1){
2850 this.clearIOSView();
2852 if(this.allowBlank) {
2854 var default_text = '-- SELECT --';
2856 if(this.placeholder.length){
2857 default_text = this.placeholder;
2860 if(this.emptyTitle.length){
2861 default_text += ' - ' + this.emptyTitle + ' -';
2864 var opt = this.inputEl().createChild({
2871 o[this.valueField] = 0;
2872 o[this.displayField] = default_text;
2874 this.ios_options.push({
2881 this.store.data.each(function(d, rowIndex){
2885 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2886 html = d.data[this.displayField];
2891 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2892 value = d.data[this.valueField];
2901 if(this.value == d.data[this.valueField]){
2902 option['selected'] = true;
2905 var opt = this.inputEl().createChild(option);
2907 this.ios_options.push({
2914 this.inputEl().on('change', function(){
2915 this.fireEvent('select', this);
2920 clearIOSView: function()
2922 this.inputEl().dom.innerHTML = '';
2924 this.ios_options = [];
2927 setIOSValue: function(v)
2931 if(!this.ios_options){
2935 Roo.each(this.ios_options, function(opts){
2937 opts.el.dom.removeAttribute('selected');
2939 if(opts.data[this.valueField] != v){
2943 opts.el.dom.setAttribute('selected', true);
2949 * @cfg {Boolean} grow
2953 * @cfg {Number} growMin
2957 * @cfg {Number} growMax
2966 Roo.apply(Roo.bootstrap.ComboBox, {
2970 cls: 'modal-header',
2992 cls: 'list-group-item',
2996 cls: 'roo-combobox-list-group-item-value'
3000 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3014 listItemCheckbox : {
3016 cls: 'list-group-item',
3020 cls: 'roo-combobox-list-group-item-value'
3024 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3040 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3045 cls: 'modal-footer',
3053 cls: 'col-xs-6 text-left',
3056 cls: 'btn btn-danger roo-touch-view-cancel',
3062 cls: 'col-xs-6 text-right',
3065 cls: 'btn btn-success roo-touch-view-ok',
3076 Roo.apply(Roo.bootstrap.ComboBox, {
3078 touchViewTemplate : {
3080 cls: 'modal fade roo-combobox-touch-view',
3084 cls: 'modal-dialog',
3085 style : 'position:fixed', // we have to fix position....
3089 cls: 'modal-content',
3091 Roo.bootstrap.ComboBox.header,
3092 Roo.bootstrap.ComboBox.body,
3093 Roo.bootstrap.ComboBox.footer