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 '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
147 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
151 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
153 listWidth: undefined,
155 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
156 * mode = 'remote' or 'text' if mode = 'local')
158 displayField: undefined,
161 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
162 * mode = 'remote' or 'value' if mode = 'local').
163 * Note: use of a valueField requires the user make a selection
164 * in order for a value to be mapped.
166 valueField: undefined,
168 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
173 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
174 * field's data value (defaults to the underlying DOM element's name)
176 hiddenName: undefined,
178 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
182 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
184 selectedClass: 'active',
187 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
191 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
192 * anchor positions (defaults to 'tl-bl')
196 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
200 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
201 * query specified by the allQuery config option (defaults to 'query')
203 triggerAction: 'query',
205 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
206 * (defaults to 4, does not apply if editable = false)
210 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
211 * delay (typeAheadDelay) if it matches a known value (defaults to false)
215 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
216 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
220 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
221 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
225 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
226 * when editable = true (defaults to false)
230 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
234 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
235 * when mode = 'remote' (defaults to 'Loading...')
237 loadingText: 'Loading...',
239 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
243 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
247 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
248 * traditional select (defaults to true)
252 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
256 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
260 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
261 * listWidth has a higher value)
265 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
266 * allow the user to set arbitrary text into the field (defaults to false)
268 forceSelection:false,
270 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
271 * if typeAhead = true (defaults to 250)
273 typeAheadDelay : 250,
275 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
276 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
278 valueNotFoundText : undefined,
280 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
285 * @cfg {Boolean} disableClear Disable showing of clear button.
287 disableClear : false,
289 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
294 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
299 * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
301 invalidClass : "has-warning",
304 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
306 validClass : "has-success",
309 * @cfg {Boolean} specialFilter (true|false) special filter default false
311 specialFilter : false,
314 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
316 mobileTouchView : true,
319 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
321 useNativeIOS : false,
324 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
326 mobile_restrict_height : false,
340 btnPosition : 'right',
342 showToggleBtn : true,
344 emptyResultText: 'Empty',
345 triggerText : 'Select',
348 // element that contains real text value.. (when hidden is used..)
350 getAutoCreate : function()
355 * Render classic select for iso
358 if(Roo.isIOS && this.useNativeIOS){
359 cfg = this.getAutoCreateNativeIOS();
367 if(Roo.isTouch && this.mobileTouchView){
368 cfg = this.getAutoCreateTouchView();
376 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
381 * ComboBox with tickable selections
384 var align = this.labelAlign || this.parentLabelAlign();
387 cls : 'form-group roo-combobox-tickable' //input-group
390 var btn_text_select = '';
391 var btn_text_done = '';
392 var btn_text_cancel = '';
394 if (this.btn_text_show) {
395 btn_text_select = 'Select';
396 btn_text_done = 'Done';
397 btn_text_cancel = 'Cancel';
402 cls : 'tickable-buttons',
407 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
408 //html : this.triggerText
409 html: btn_text_select
415 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
423 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
425 html: btn_text_cancel
433 cls: 'roo-select2-search-field-input'
439 Roo.each(buttons.cn, function(c){
441 c.cls += ' btn-' + _this.size;
444 if (_this.disabled) {
451 style : 'display: contents',
456 cls: 'form-hidden-field'
460 cls: 'roo-select2-choices',
464 cls: 'roo-select2-search-field',
475 cls: 'roo-select2-container input-group roo-select2-container-multi',
481 // cls: 'typeahead typeahead-long dropdown-menu',
482 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
487 if(this.hasFeedback && !this.allowBlank){
491 cls: 'glyphicon form-control-feedback'
494 combobox.cn.push(feedback);
499 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
500 tooltip : 'This field is required'
502 if (Roo.bootstrap.version == 4) {
505 style : 'display:none'
508 if (align ==='left' && this.fieldLabel.length) {
510 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
517 cls : 'control-label col-form-label',
518 html : this.fieldLabel
530 var labelCfg = cfg.cn[1];
531 var contentCfg = cfg.cn[2];
534 if(this.indicatorpos == 'right'){
540 cls : 'control-label col-form-label',
544 html : this.fieldLabel
560 labelCfg = cfg.cn[0];
561 contentCfg = cfg.cn[1];
565 if(this.labelWidth > 12){
566 labelCfg.style = "width: " + this.labelWidth + 'px';
569 if(this.labelWidth < 13 && this.labelmd == 0){
570 this.labelmd = this.labelWidth;
573 if(this.labellg > 0){
574 labelCfg.cls += ' col-lg-' + this.labellg;
575 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
578 if(this.labelmd > 0){
579 labelCfg.cls += ' col-md-' + this.labelmd;
580 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
583 if(this.labelsm > 0){
584 labelCfg.cls += ' col-sm-' + this.labelsm;
585 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
588 if(this.labelxs > 0){
589 labelCfg.cls += ' col-xs-' + this.labelxs;
590 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
594 } else if ( this.fieldLabel.length) {
595 // Roo.log(" label");
600 //cls : 'input-group-addon',
601 html : this.fieldLabel
606 if(this.indicatorpos == 'right'){
610 //cls : 'input-group-addon',
611 html : this.fieldLabel
621 // Roo.log(" no label && no align");
628 ['xs','sm','md','lg'].map(function(size){
629 if (settings[size]) {
630 cfg.cls += ' col-' + size + '-' + settings[size];
638 _initEventsCalled : false,
641 initEvents: function()
643 if (this._initEventsCalled) { // as we call render... prevent looping...
646 this._initEventsCalled = true;
649 throw "can not find store for combo";
652 this.indicator = this.indicatorEl();
654 this.store = Roo.factory(this.store, Roo.data);
655 this.store.parent = this;
657 // if we are building from html. then this element is so complex, that we can not really
658 // use the rendered HTML.
659 // so we have to trash and replace the previous code.
660 if (Roo.XComponent.build_from_html) {
661 // remove this element....
662 var e = this.el.dom, k=0;
663 while (e ) { e = e.previousSibling; ++k;}
668 this.rendered = false;
670 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);
727 this.list.on('scroll', this.onViewScroll, this);
730 this.list.swallowEvent('mousewheel');
731 this.assetHeight = 0;
734 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
735 this.assetHeight += this.header.getHeight();
738 this.innerList = this.list.createChild({cls:cls+'-inner'});
739 this.innerList.on('mouseover', this.onViewOver, this);
740 this.innerList.on('mousemove', this.onViewMove, this);
741 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
743 if(this.allowBlank && !this.pageSize && !this.disableClear){
744 this.footer = this.list.createChild({cls:cls+'-ft'});
745 this.pageTb = new Roo.Toolbar(this.footer);
749 this.footer = this.list.createChild({cls:cls+'-ft'});
750 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
751 {pageSize: this.pageSize});
755 if (this.pageTb && this.allowBlank && !this.disableClear) {
757 this.pageTb.add(new Roo.Toolbar.Fill(), {
758 cls: 'x-btn-icon x-btn-clear',
764 _this.onSelect(false, -1);
769 this.assetHeight += this.footer.getHeight();
774 this.tpl = Roo.bootstrap.version == 4 ?
775 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
776 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
779 this.view = new Roo.View(this.list, this.tpl, {
780 singleSelect:true, store: this.store, selectedClass: this.selectedClass
782 //this.view.wrapEl.setDisplayed(false);
783 this.view.on('click', this.onViewClick, this);
786 this.store.on('beforeload', this.onBeforeLoad, this);
787 this.store.on('load', this.onLoad, this);
788 this.store.on('loadexception', this.onLoadException, this);
791 this.resizer = new Roo.Resizable(this.list, {
792 pinned:true, handles:'se'
794 this.resizer.on('resize', function(r, w, h){
795 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
797 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
798 this.restrictHeight();
800 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
804 this.editable = true;
805 this.setEditable(false);
810 if (typeof(this.events.add.listeners) != 'undefined') {
812 this.addicon = this.wrap.createChild(
813 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
815 this.addicon.on('click', function(e) {
816 this.fireEvent('add', this);
819 if (typeof(this.events.edit.listeners) != 'undefined') {
821 this.editicon = this.wrap.createChild(
822 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
824 this.editicon.setStyle('margin-left', '40px');
826 this.editicon.on('click', function(e) {
828 // we fire even if inothing is selected..
829 this.fireEvent('edit', this, this.lastData );
835 this.keyNav = new Roo.KeyNav(this.inputEl(), {
837 this.inKeyMode = true;
841 "down" : function(e){
842 if(!this.isExpanded()){
843 this.onTriggerClick();
845 this.inKeyMode = true;
850 "enter" : function(e){
851 // this.onViewClick();
855 if(this.fireEvent("specialkey", this, e)){
856 this.onViewClick(false);
869 if(this.fireEvent("specialkey", this, e)){
870 this.onViewClick(false);
878 doRelay : function(foo, bar, hname){
879 if(hname == 'down' || this.scope.isExpanded()){
880 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
889 this.queryDelay = Math.max(this.queryDelay || 10,
890 this.mode == 'local' ? 10 : 250);
893 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
896 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
898 if(this.editable !== false){
899 this.inputEl().on("keyup", this.onKeyUp, this);
901 if(this.forceSelection){
902 this.inputEl().on('blur', this.doForce, this);
906 this.choices = this.el.select('ul.roo-select2-choices', true).first();
907 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
911 initTickableEvents: function()
917 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
919 this.hiddenField.dom.value =
920 this.hiddenValue !== undefined ? this.hiddenValue :
921 this.value !== undefined ? this.value : '';
923 // prevent input submission
924 this.el.dom.removeAttribute('name');
925 this.hiddenField.dom.setAttribute('name', this.hiddenName);
930 // this.list = this.el.select('ul.dropdown-menu',true).first();
932 this.choices = this.el.select('ul.roo-select2-choices', true).first();
933 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
934 if(this.triggerList){
935 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
938 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
939 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
941 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
942 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
944 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
945 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
947 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
948 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
949 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
952 this.cancelBtn.hide();
957 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
958 _this.list.setWidth(lw);
961 this.list.on('mouseover', this.onViewOver, this);
962 this.list.on('mousemove', this.onViewMove, this);
964 this.list.on('scroll', this.onViewScroll, this);
967 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
968 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
971 this.view = new Roo.View(this.list, this.tpl, {
976 selectedClass: this.selectedClass
979 //this.view.wrapEl.setDisplayed(false);
980 this.view.on('click', this.onViewClick, this);
984 this.store.on('beforeload', this.onBeforeLoad, this);
985 this.store.on('load', this.onLoad, this);
986 this.store.on('loadexception', this.onLoadException, this);
989 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
991 this.inKeyMode = true;
995 "down" : function(e){
996 this.inKeyMode = true;
1000 "enter" : function(e){
1001 if(this.fireEvent("specialkey", this, e)){
1002 this.onViewClick(false);
1008 "esc" : function(e){
1009 this.onTickableFooterButtonClick(e, false, false);
1012 "tab" : function(e){
1013 this.fireEvent("specialkey", this, e);
1015 this.onTickableFooterButtonClick(e, false, false);
1022 doRelay : function(e, fn, key){
1023 if(this.scope.isExpanded()){
1024 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1033 this.queryDelay = Math.max(this.queryDelay || 10,
1034 this.mode == 'local' ? 10 : 250);
1037 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1040 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1043 if(this.editable !== false){
1044 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1047 this.indicator = this.indicatorEl();
1050 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1051 this.indicator.hide();
1056 onDestroy : function(){
1058 this.view.setStore(null);
1059 this.view.el.removeAllListeners();
1060 this.view.el.remove();
1061 this.view.purgeListeners();
1064 this.list.dom.innerHTML = '';
1068 this.store.un('beforeload', this.onBeforeLoad, this);
1069 this.store.un('load', this.onLoad, this);
1070 this.store.un('loadexception', this.onLoadException, this);
1072 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1076 fireKey : function(e){
1077 if(e.isNavKeyPress() && !this.list.isVisible()){
1078 this.fireEvent("specialkey", this, e);
1083 onResize: function(w, h){
1084 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1086 // if(typeof w != 'number'){
1087 // // we do not handle it!?!?
1090 // var tw = this.trigger.getWidth();
1091 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1092 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1094 // this.inputEl().setWidth( this.adjustWidth('input', x));
1096 // //this.trigger.setStyle('left', x+'px');
1098 // if(this.list && this.listWidth === undefined){
1099 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1100 // this.list.setWidth(lw);
1101 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1109 * Allow or prevent the user from directly editing the field text. If false is passed,
1110 * the user will only be able to select from the items defined in the dropdown list. This method
1111 * is the runtime equivalent of setting the 'editable' config option at config time.
1112 * @param {Boolean} value True to allow the user to directly edit the field text
1114 setEditable : function(value){
1115 if(value == this.editable){
1118 this.editable = value;
1120 this.inputEl().dom.setAttribute('readOnly', true);
1121 this.inputEl().on('mousedown', this.onTriggerClick, this);
1122 this.inputEl().addClass('x-combo-noedit');
1124 this.inputEl().dom.setAttribute('readOnly', false);
1125 this.inputEl().un('mousedown', this.onTriggerClick, this);
1126 this.inputEl().removeClass('x-combo-noedit');
1132 onBeforeLoad : function(combo,opts){
1137 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1139 this.restrictHeight();
1140 this.selectedIndex = -1;
1144 onLoad : function(){
1146 this.hasQuery = false;
1152 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1153 this.loading.hide();
1156 if(this.store.getCount() > 0){
1159 this.restrictHeight();
1160 if(this.lastQuery == this.allQuery){
1161 if(this.editable && !this.tickable){
1162 this.inputEl().dom.select();
1166 !this.selectByValue(this.value, true) &&
1169 !this.store.lastOptions ||
1170 typeof(this.store.lastOptions.add) == 'undefined' ||
1171 this.store.lastOptions.add != true
1174 this.select(0, true);
1180 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1181 this.taTask.delay(this.typeAheadDelay);
1185 this.onEmptyResults();
1191 onLoadException : function()
1193 this.hasQuery = false;
1195 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1196 this.loading.hide();
1199 if(this.tickable && this.editable){
1204 // only causes errors at present
1205 //Roo.log(this.store.reader.jsonData);
1206 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1208 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1214 onTypeAhead : function(){
1215 if(this.store.getCount() > 0){
1216 var r = this.store.getAt(0);
1217 var newValue = r.data[this.displayField];
1218 var len = newValue.length;
1219 var selStart = this.getRawValue().length;
1221 if(selStart != len){
1222 this.setRawValue(newValue);
1223 this.selectText(selStart, newValue.length);
1229 onSelect : function(record, index){
1231 if(this.fireEvent('beforeselect', this, record, index) !== false){
1233 this.setFromData(index > -1 ? record.data : false);
1236 this.fireEvent('select', this, record, index);
1241 * Returns the currently selected field value or empty string if no value is set.
1242 * @return {String} value The selected value
1244 getValue : function()
1246 if(Roo.isIOS && this.useNativeIOS){
1247 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1251 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1254 if(this.valueField){
1255 return typeof this.value != 'undefined' ? this.value : '';
1257 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1261 getRawValue : function()
1263 if(Roo.isIOS && this.useNativeIOS){
1264 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1267 var v = this.inputEl().getValue();
1273 * Clears any text/value currently set in the field
1275 clearValue : function(){
1277 if(this.hiddenField){
1278 this.hiddenField.dom.value = '';
1281 this.setRawValue('');
1282 this.lastSelectionText = '';
1283 this.lastData = false;
1285 var close = this.closeTriggerEl();
1296 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1297 * will be displayed in the field. If the value does not match the data value of an existing item,
1298 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1299 * Otherwise the field will be blank (although the value will still be set).
1300 * @param {String} value The value to match
1302 setValue : function(v)
1304 if(Roo.isIOS && this.useNativeIOS){
1305 this.setIOSValue(v);
1315 if(this.valueField){
1316 var r = this.findRecord(this.valueField, v);
1318 text = r.data[this.displayField];
1319 }else if(this.valueNotFoundText !== undefined){
1320 text = this.valueNotFoundText;
1323 this.lastSelectionText = text;
1324 if(this.hiddenField){
1325 this.hiddenField.dom.value = v;
1327 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1330 var close = this.closeTriggerEl();
1333 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1339 * @property {Object} the last set data for the element
1344 * Sets the value of the field based on a object which is related to the record format for the store.
1345 * @param {Object} value the value to set as. or false on reset?
1347 setFromData : function(o){
1354 var dv = ''; // display value
1355 var vv = ''; // value value..
1357 if (this.displayField) {
1358 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1360 // this is an error condition!!!
1361 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1364 if(this.valueField){
1365 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1368 var close = this.closeTriggerEl();
1371 if(dv.length || vv * 1 > 0){
1373 this.blockFocus=true;
1379 if(this.hiddenField){
1380 this.hiddenField.dom.value = vv;
1382 this.lastSelectionText = dv;
1383 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1387 // no hidden field.. - we store the value in 'value', but still display
1388 // display field!!!!
1389 this.lastSelectionText = dv;
1390 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1398 // overridden so that last data is reset..
1405 this.setValue(this.originalValue);
1406 //this.clearInvalid();
1407 this.lastData = false;
1409 this.view.clearSelections();
1415 findRecord : function(prop, value){
1417 if(this.store.getCount() > 0){
1418 this.store.each(function(r){
1419 if(r.data[prop] == value){
1431 // returns hidden if it's set..
1432 if (!this.rendered) {return ''};
1433 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1437 onViewMove : function(e, t){
1438 this.inKeyMode = false;
1442 onViewOver : function(e, t){
1443 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1446 var item = this.view.findItemFromChild(t);
1449 var index = this.view.indexOf(item);
1450 this.select(index, false);
1455 onViewClick : function(view, doFocus, el, e)
1457 var index = this.view.getSelectedIndexes()[0];
1459 var r = this.store.getAt(index);
1463 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1470 Roo.each(this.tickItems, function(v,k){
1472 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1474 _this.tickItems.splice(k, 1);
1476 if(typeof(e) == 'undefined' && view == false){
1477 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1489 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1490 this.tickItems.push(r.data);
1493 if(typeof(e) == 'undefined' && view == false){
1494 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1501 this.onSelect(r, index);
1503 if(doFocus !== false && !this.blockFocus){
1504 this.inputEl().focus();
1509 restrictHeight : function(){
1510 //this.innerList.dom.style.height = '';
1511 //var inner = this.innerList.dom;
1512 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1513 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1514 //this.list.beginUpdate();
1515 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1516 this.list.alignTo(this.inputEl(), this.listAlign);
1517 this.list.alignTo(this.inputEl(), this.listAlign);
1518 //this.list.endUpdate();
1522 onEmptyResults : function(){
1524 if(this.tickable && this.editable){
1525 this.hasFocus = false;
1526 this.restrictHeight();
1534 * Returns true if the dropdown list is expanded, else false.
1536 isExpanded : function(){
1537 return this.list.isVisible();
1541 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1542 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1543 * @param {String} value The data value of the item to select
1544 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1545 * selected item if it is not currently in view (defaults to true)
1546 * @return {Boolean} True if the value matched an item in the list, else false
1548 selectByValue : function(v, scrollIntoView){
1549 if(v !== undefined && v !== null){
1550 var r = this.findRecord(this.valueField || this.displayField, v);
1552 this.select(this.store.indexOf(r), scrollIntoView);
1560 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1561 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1562 * @param {Number} index The zero-based index of the list item to select
1563 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1564 * selected item if it is not currently in view (defaults to true)
1566 select : function(index, scrollIntoView){
1567 this.selectedIndex = index;
1568 this.view.select(index);
1569 if(scrollIntoView !== false){
1570 var el = this.view.getNode(index);
1572 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1575 this.list.scrollChildIntoView(el, false);
1581 selectNext : function(){
1582 var ct = this.store.getCount();
1584 if(this.selectedIndex == -1){
1586 }else if(this.selectedIndex < ct-1){
1587 this.select(this.selectedIndex+1);
1593 selectPrev : function(){
1594 var ct = this.store.getCount();
1596 if(this.selectedIndex == -1){
1598 }else if(this.selectedIndex != 0){
1599 this.select(this.selectedIndex-1);
1605 onKeyUp : function(e){
1606 if(this.editable !== false && !e.isSpecialKey()){
1607 this.lastKey = e.getKey();
1608 this.dqTask.delay(this.queryDelay);
1613 validateBlur : function(){
1614 return !this.list || !this.list.isVisible();
1618 initQuery : function(){
1620 var v = this.getRawValue();
1622 if(this.tickable && this.editable){
1623 v = this.tickableInputEl().getValue();
1630 doForce : function(){
1631 if(this.inputEl().dom.value.length > 0){
1632 this.inputEl().dom.value =
1633 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1639 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1640 * query allowing the query action to be canceled if needed.
1641 * @param {String} query The SQL query to execute
1642 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1643 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1644 * saved in the current store (defaults to false)
1646 doQuery : function(q, forceAll){
1648 if(q === undefined || q === null){
1657 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1662 forceAll = qe.forceAll;
1663 if(forceAll === true || (q.length >= this.minChars)){
1665 this.hasQuery = true;
1667 if(this.lastQuery != q || this.alwaysQuery){
1669 if(this.mode == 'local'){
1670 this.selectedIndex = -1;
1672 this.store.clearFilter();
1675 if(this.specialFilter){
1676 this.fireEvent('specialfilter', this);
1681 this.store.filter(this.displayField, q);
1684 this.store.fireEvent("datachanged", this.store);
1691 this.store.baseParams[this.queryParam] = q;
1693 var options = {params : this.getParams(q)};
1697 options.params.start = this.page * this.pageSize;
1700 this.store.load(options);
1703 * this code will make the page width larger, at the beginning, the list not align correctly,
1704 * we should expand the list on onLoad
1710 this.selectedIndex = -1;
1715 this.loadNext = false;
1719 getParams : function(q){
1721 //p[this.queryParam] = q;
1725 p.limit = this.pageSize;
1731 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1733 collapse : function(){
1734 if(!this.isExpanded()){
1740 this.hasFocus = false;
1744 this.cancelBtn.hide();
1745 this.trigger.show();
1748 this.tickableInputEl().dom.value = '';
1749 this.tickableInputEl().blur();
1754 Roo.get(document).un('mousedown', this.collapseIf, this);
1755 Roo.get(document).un('mousewheel', this.collapseIf, this);
1756 if (!this.editable) {
1757 Roo.get(document).un('keydown', this.listKeyPress, this);
1759 this.fireEvent('collapse', this);
1765 collapseIf : function(e){
1766 var in_combo = e.within(this.el);
1767 var in_list = e.within(this.list);
1768 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1770 if (in_combo || in_list || is_list) {
1771 //e.stopPropagation();
1776 this.onTickableFooterButtonClick(e, false, false);
1784 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1786 expand : function(){
1788 if(this.isExpanded() || !this.hasFocus){
1792 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1793 this.list.setWidth(lw);
1799 this.restrictHeight();
1803 this.tickItems = Roo.apply([], this.item);
1806 this.cancelBtn.show();
1807 this.trigger.hide();
1810 this.tickableInputEl().focus();
1815 Roo.get(document).on('mousedown', this.collapseIf, this);
1816 Roo.get(document).on('mousewheel', this.collapseIf, this);
1817 if (!this.editable) {
1818 Roo.get(document).on('keydown', this.listKeyPress, this);
1821 this.fireEvent('expand', this);
1825 // Implements the default empty TriggerField.onTriggerClick function
1826 onTriggerClick : function(e)
1828 Roo.log('trigger click');
1830 if(this.disabled || !this.triggerList){
1835 this.loadNext = false;
1837 if(this.isExpanded()){
1839 if (!this.blockFocus) {
1840 this.inputEl().focus();
1844 this.hasFocus = true;
1845 if(this.triggerAction == 'all') {
1846 this.doQuery(this.allQuery, true);
1848 this.doQuery(this.getRawValue());
1850 if (!this.blockFocus) {
1851 this.inputEl().focus();
1856 onTickableTriggerClick : function(e)
1863 this.loadNext = false;
1864 this.hasFocus = true;
1866 if(this.triggerAction == 'all') {
1867 this.doQuery(this.allQuery, true);
1869 this.doQuery(this.getRawValue());
1873 onSearchFieldClick : function(e)
1875 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1876 this.onTickableFooterButtonClick(e, false, false);
1880 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1885 this.loadNext = false;
1886 this.hasFocus = true;
1888 if(this.triggerAction == 'all') {
1889 this.doQuery(this.allQuery, true);
1891 this.doQuery(this.getRawValue());
1895 listKeyPress : function(e)
1897 //Roo.log('listkeypress');
1898 // scroll to first matching element based on key pres..
1899 if (e.isSpecialKey()) {
1902 var k = String.fromCharCode(e.getKey()).toUpperCase();
1905 var csel = this.view.getSelectedNodes();
1906 var cselitem = false;
1908 var ix = this.view.indexOf(csel[0]);
1909 cselitem = this.store.getAt(ix);
1910 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1916 this.store.each(function(v) {
1918 // start at existing selection.
1919 if (cselitem.id == v.id) {
1925 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1926 match = this.store.indexOf(v);
1932 if (match === false) {
1933 return true; // no more action?
1936 this.view.select(match);
1937 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1938 sn.scrollIntoView(sn.dom.parentNode, false);
1941 onViewScroll : function(e, t){
1943 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){
1947 this.hasQuery = true;
1949 this.loading = this.list.select('.loading', true).first();
1951 if(this.loading === null){
1952 this.list.createChild({
1954 cls: 'loading roo-select2-more-results roo-select2-active',
1955 html: 'Loading more results...'
1958 this.loading = this.list.select('.loading', true).first();
1960 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1962 this.loading.hide();
1965 this.loading.show();
1970 this.loadNext = true;
1972 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1977 addItem : function(o)
1979 var dv = ''; // display value
1981 if (this.displayField) {
1982 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1984 // this is an error condition!!!
1985 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1992 var choice = this.choices.createChild({
1994 cls: 'roo-select2-search-choice',
2003 cls: 'roo-select2-search-choice-close fa fa-times',
2008 }, this.searchField);
2010 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2012 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2020 this.inputEl().dom.value = '';
2025 onRemoveItem : function(e, _self, o)
2029 this.lastItem = Roo.apply([], this.item);
2031 var index = this.item.indexOf(o.data) * 1;
2034 Roo.log('not this item?!');
2038 this.item.splice(index, 1);
2043 this.fireEvent('remove', this, e);
2049 syncValue : function()
2051 if(!this.item.length){
2058 Roo.each(this.item, function(i){
2059 if(_this.valueField){
2060 value.push(i[_this.valueField]);
2067 this.value = value.join(',');
2069 if(this.hiddenField){
2070 this.hiddenField.dom.value = this.value;
2073 this.store.fireEvent("datachanged", this.store);
2078 clearItem : function()
2086 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2094 if(this.tickable && !Roo.isTouch){
2095 this.view.refresh();
2099 inputEl: function ()
2101 if(Roo.isIOS && this.useNativeIOS){
2102 return this.el.select('select.roo-ios-select', true).first();
2105 if(Roo.isTouch && this.mobileTouchView){
2106 return this.el.select('input.form-control',true).first();
2110 return this.searchField;
2113 return this.el.select('input.form-control',true).first();
2116 onTickableFooterButtonClick : function(e, btn, el)
2120 this.lastItem = Roo.apply([], this.item);
2122 if(btn && btn.name == 'cancel'){
2123 this.tickItems = Roo.apply([], this.item);
2132 Roo.each(this.tickItems, function(o){
2140 validate : function()
2142 if(this.getVisibilityEl().hasClass('hidden')){
2146 var v = this.getRawValue();
2149 v = this.getValue();
2152 if(this.disabled || this.allowBlank || v.length){
2161 tickableInputEl : function()
2163 if(!this.tickable || !this.editable){
2164 return this.inputEl();
2167 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2171 getAutoCreateTouchView : function()
2176 cls: 'form-group' //input-group
2182 type : this.inputType,
2183 cls : 'form-control x-combo-noedit',
2184 autocomplete: 'new-password',
2185 placeholder : this.placeholder || '',
2190 input.name = this.name;
2194 input.cls += ' input-' + this.size;
2197 if (this.disabled) {
2198 input.disabled = true;
2209 inputblock.cls += ' input-group';
2211 inputblock.cn.unshift({
2213 cls : 'input-group-addon input-group-prepend input-group-text',
2218 if(this.removable && !this.multiple){
2219 inputblock.cls += ' roo-removable';
2221 inputblock.cn.push({
2224 cls : 'roo-combo-removable-btn close'
2228 if(this.hasFeedback && !this.allowBlank){
2230 inputblock.cls += ' has-feedback';
2232 inputblock.cn.push({
2234 cls: 'glyphicon form-control-feedback'
2241 inputblock.cls += (this.before) ? '' : ' input-group';
2243 inputblock.cn.push({
2245 cls : 'input-group-addon input-group-append input-group-text',
2251 var ibwrap = inputblock;
2256 cls: 'roo-select2-choices',
2260 cls: 'roo-select2-search-field',
2273 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2278 cls: 'form-hidden-field'
2284 if(!this.multiple && this.showToggleBtn){
2290 if (this.caret != false) {
2293 cls: 'fa fa-' + this.caret
2300 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2302 Roo.bootstrap.version == 3 ? caret : '',
2305 cls: 'combobox-clear',
2319 combobox.cls += ' roo-select2-container-multi';
2322 var align = this.labelAlign || this.parentLabelAlign();
2324 if (align ==='left' && this.fieldLabel.length) {
2329 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2330 tooltip : 'This field is required'
2334 cls : 'control-label col-form-label',
2335 html : this.fieldLabel
2346 var labelCfg = cfg.cn[1];
2347 var contentCfg = cfg.cn[2];
2350 if(this.indicatorpos == 'right'){
2355 cls : 'control-label col-form-label',
2359 html : this.fieldLabel
2363 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2364 tooltip : 'This field is required'
2377 labelCfg = cfg.cn[0];
2378 contentCfg = cfg.cn[1];
2383 if(this.labelWidth > 12){
2384 labelCfg.style = "width: " + this.labelWidth + 'px';
2387 if(this.labelWidth < 13 && this.labelmd == 0){
2388 this.labelmd = this.labelWidth;
2391 if(this.labellg > 0){
2392 labelCfg.cls += ' col-lg-' + this.labellg;
2393 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2396 if(this.labelmd > 0){
2397 labelCfg.cls += ' col-md-' + this.labelmd;
2398 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2401 if(this.labelsm > 0){
2402 labelCfg.cls += ' col-sm-' + this.labelsm;
2403 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2406 if(this.labelxs > 0){
2407 labelCfg.cls += ' col-xs-' + this.labelxs;
2408 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2412 } else if ( this.fieldLabel.length) {
2416 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2417 tooltip : 'This field is required'
2421 cls : 'control-label',
2422 html : this.fieldLabel
2433 if(this.indicatorpos == 'right'){
2437 cls : 'control-label',
2438 html : this.fieldLabel,
2442 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2443 tooltip : 'This field is required'
2460 var settings = this;
2462 ['xs','sm','md','lg'].map(function(size){
2463 if (settings[size]) {
2464 cfg.cls += ' col-' + size + '-' + settings[size];
2471 initTouchView : function()
2473 this.renderTouchView();
2475 this.touchViewEl.on('scroll', function(){
2476 this.el.dom.scrollTop = 0;
2479 this.originalValue = this.getValue();
2481 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2483 this.inputEl().on("click", this.showTouchView, this);
2484 if (this.triggerEl) {
2485 this.triggerEl.on("click", this.showTouchView, this);
2489 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2490 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2492 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2494 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2495 this.store.on('load', this.onTouchViewLoad, this);
2496 this.store.on('loadexception', this.onTouchViewLoadException, this);
2498 if(this.hiddenName){
2500 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2502 this.hiddenField.dom.value =
2503 this.hiddenValue !== undefined ? this.hiddenValue :
2504 this.value !== undefined ? this.value : '';
2506 this.el.dom.removeAttribute('name');
2507 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2511 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2512 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2515 if(this.removable && !this.multiple){
2516 var close = this.closeTriggerEl();
2518 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2519 close.on('click', this.removeBtnClick, this, close);
2523 * fix the bug in Safari iOS8
2525 this.inputEl().on("focus", function(e){
2526 document.activeElement.blur();
2529 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2536 renderTouchView : function()
2538 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2539 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2541 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2542 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2544 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2545 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2546 this.touchViewBodyEl.setStyle('overflow', 'auto');
2548 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2549 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2551 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2552 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2556 showTouchView : function()
2562 this.touchViewHeaderEl.hide();
2564 if(this.modalTitle.length){
2565 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2566 this.touchViewHeaderEl.show();
2569 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2570 this.touchViewEl.show();
2572 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2574 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2575 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2577 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2579 if(this.modalTitle.length){
2580 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2583 this.touchViewBodyEl.setHeight(bodyHeight);
2587 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2589 this.touchViewEl.addClass('in');
2592 if(this._touchViewMask){
2593 Roo.get(document.body).addClass("x-body-masked");
2594 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2595 this._touchViewMask.setStyle('z-index', 10000);
2596 this._touchViewMask.addClass('show');
2599 this.doTouchViewQuery();
2603 hideTouchView : function()
2605 this.touchViewEl.removeClass('in');
2609 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2611 this.touchViewEl.setStyle('display', 'none');
2614 if(this._touchViewMask){
2615 this._touchViewMask.removeClass('show');
2616 Roo.get(document.body).removeClass("x-body-masked");
2620 setTouchViewValue : function()
2627 Roo.each(this.tickItems, function(o){
2632 this.hideTouchView();
2635 doTouchViewQuery : function()
2644 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2648 if(!this.alwaysQuery || this.mode == 'local'){
2649 this.onTouchViewLoad();
2656 onTouchViewBeforeLoad : function(combo,opts)
2662 onTouchViewLoad : function()
2664 if(this.store.getCount() < 1){
2665 this.onTouchViewEmptyResults();
2669 this.clearTouchView();
2671 var rawValue = this.getRawValue();
2673 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2675 this.tickItems = [];
2677 this.store.data.each(function(d, rowIndex){
2678 var row = this.touchViewListGroup.createChild(template);
2680 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2681 row.addClass(d.data.cls);
2684 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2687 html : d.data[this.displayField]
2690 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2691 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2694 row.removeClass('selected');
2695 if(!this.multiple && this.valueField &&
2696 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2699 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2700 row.addClass('selected');
2703 if(this.multiple && this.valueField &&
2704 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2708 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2709 this.tickItems.push(d.data);
2712 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2716 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2718 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2720 if(this.modalTitle.length){
2721 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2724 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2726 if(this.mobile_restrict_height && listHeight < bodyHeight){
2727 this.touchViewBodyEl.setHeight(listHeight);
2732 if(firstChecked && listHeight > bodyHeight){
2733 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2738 onTouchViewLoadException : function()
2740 this.hideTouchView();
2743 onTouchViewEmptyResults : function()
2745 this.clearTouchView();
2747 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2749 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2753 clearTouchView : function()
2755 this.touchViewListGroup.dom.innerHTML = '';
2758 onTouchViewClick : function(e, el, o)
2763 var rowIndex = o.rowIndex;
2765 var r = this.store.getAt(rowIndex);
2767 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2770 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2771 c.dom.removeAttribute('checked');
2774 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2776 this.setFromData(r.data);
2778 var close = this.closeTriggerEl();
2784 this.hideTouchView();
2786 this.fireEvent('select', this, r, rowIndex);
2791 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2792 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2793 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2797 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2798 this.addItem(r.data);
2799 this.tickItems.push(r.data);
2803 getAutoCreateNativeIOS : function()
2806 cls: 'form-group' //input-group,
2811 cls : 'roo-ios-select'
2815 combobox.name = this.name;
2818 if (this.disabled) {
2819 combobox.disabled = true;
2822 var settings = this;
2824 ['xs','sm','md','lg'].map(function(size){
2825 if (settings[size]) {
2826 cfg.cls += ' col-' + size + '-' + settings[size];
2836 initIOSView : function()
2838 this.store.on('load', this.onIOSViewLoad, this);
2843 onIOSViewLoad : function()
2845 if(this.store.getCount() < 1){
2849 this.clearIOSView();
2851 if(this.allowBlank) {
2853 var default_text = '-- SELECT --';
2855 if(this.placeholder.length){
2856 default_text = this.placeholder;
2859 if(this.emptyTitle.length){
2860 default_text += ' - ' + this.emptyTitle + ' -';
2863 var opt = this.inputEl().createChild({
2870 o[this.valueField] = 0;
2871 o[this.displayField] = default_text;
2873 this.ios_options.push({
2880 this.store.data.each(function(d, rowIndex){
2884 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2885 html = d.data[this.displayField];
2890 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2891 value = d.data[this.valueField];
2900 if(this.value == d.data[this.valueField]){
2901 option['selected'] = true;
2904 var opt = this.inputEl().createChild(option);
2906 this.ios_options.push({
2913 this.inputEl().on('change', function(){
2914 this.fireEvent('select', this);
2919 clearIOSView: function()
2921 this.inputEl().dom.innerHTML = '';
2923 this.ios_options = [];
2926 setIOSValue: function(v)
2930 if(!this.ios_options){
2934 Roo.each(this.ios_options, function(opts){
2936 opts.el.dom.removeAttribute('selected');
2938 if(opts.data[this.valueField] != v){
2942 opts.el.dom.setAttribute('selected', true);
2948 * @cfg {Boolean} grow
2952 * @cfg {Number} growMin
2956 * @cfg {Number} growMax
2965 Roo.apply(Roo.bootstrap.ComboBox, {
2969 cls: 'modal-header',
2991 cls: 'list-group-item',
2995 cls: 'roo-combobox-list-group-item-value'
2999 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3013 listItemCheckbox : {
3015 cls: 'list-group-item',
3019 cls: 'roo-combobox-list-group-item-value'
3023 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3039 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3044 cls: 'modal-footer',
3052 cls: 'col-xs-6 text-left',
3055 cls: 'btn btn-danger roo-touch-view-cancel',
3061 cls: 'col-xs-6 text-right',
3064 cls: 'btn btn-success roo-touch-view-ok',
3075 Roo.apply(Roo.bootstrap.ComboBox, {
3077 touchViewTemplate : {
3079 cls: 'modal fade roo-combobox-touch-view',
3083 cls: 'modal-dialog',
3084 style : 'position:fixed', // we have to fix position....
3088 cls: 'modal-content',
3090 Roo.bootstrap.ComboBox.header,
3091 Roo.bootstrap.ComboBox.body,
3092 Roo.bootstrap.ComboBox.footer