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 ''
20 * @cfg {Number} width fixed with? experimental
22 * Create a new ComboBox.
23 * @param {Object} config Configuration options
25 Roo.bootstrap.ComboBox = function(config){
26 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
30 * Fires when the dropdown list is expanded
31 * @param {Roo.bootstrap.ComboBox} combo This combo box
36 * Fires when the dropdown list is collapsed
37 * @param {Roo.bootstrap.ComboBox} combo This combo box
42 * Fires before a list item is selected. Return false to cancel the selection.
43 * @param {Roo.bootstrap.ComboBox} combo This combo box
44 * @param {Roo.data.Record} record The data record returned from the underlying store
45 * @param {Number} index The index of the selected item in the dropdown list
47 'beforeselect' : true,
50 * Fires when a list item is selected
51 * @param {Roo.bootstrap.ComboBox} combo This combo box
52 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
53 * @param {Number} index The index of the selected item in the dropdown list
58 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
59 * The event object passed has these properties:
60 * @param {Roo.bootstrap.ComboBox} combo This combo box
61 * @param {String} query The query
62 * @param {Boolean} forceAll true to force "all" query
63 * @param {Boolean} cancel true to cancel the query
64 * @param {Object} e The query event object
69 * Fires when the 'add' icon is pressed (add a listener to enable add button)
70 * @param {Roo.bootstrap.ComboBox} combo This combo box
75 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
76 * @param {Roo.bootstrap.ComboBox} combo This combo box
77 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
82 * Fires when the remove value from the combobox array
83 * @param {Roo.bootstrap.ComboBox} combo This combo box
88 * Fires when the remove value from the combobox array
89 * @param {Roo.bootstrap.ComboBox} combo This combo box
93 * @event specialfilter
94 * Fires when specialfilter
95 * @param {Roo.bootstrap.ComboBox} combo This combo box
97 'specialfilter' : true,
100 * Fires when tick the element
101 * @param {Roo.bootstrap.ComboBox} combo This combo box
105 * @event touchviewdisplay
106 * Fires when touch view require special display (default is using displayField)
107 * @param {Roo.bootstrap.ComboBox} combo This combo box
108 * @param {Object} cfg set html .
110 'touchviewdisplay' : true
117 this.selectedIndex = -1;
118 if(this.mode == 'local'){
119 if(config.queryDelay === undefined){
120 this.queryDelay = 10;
122 if(config.minChars === undefined){
128 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
131 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
132 * rendering into an Roo.Editor, defaults to false)
135 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
136 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
139 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
142 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
143 * the dropdown list (defaults to undefined, with no header element)
147 * @cfg {String/Roo.Template} tpl The template to use to render the output default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
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',
349 // element that contains real text value.. (when hidden is used..)
351 getAutoCreate : function()
356 * Render classic select for iso
359 if(Roo.isIOS && this.useNativeIOS){
360 cfg = this.getAutoCreateNativeIOS();
368 if(Roo.isTouch && this.mobileTouchView){
369 cfg = this.getAutoCreateTouchView();
377 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
382 * ComboBox with tickable selections
385 var align = this.labelAlign || this.parentLabelAlign();
388 cls : 'form-group roo-combobox-tickable' //input-group
391 var btn_text_select = '';
392 var btn_text_done = '';
393 var btn_text_cancel = '';
395 if (this.btn_text_show) {
396 btn_text_select = 'Select';
397 btn_text_done = 'Done';
398 btn_text_cancel = 'Cancel';
403 cls : 'tickable-buttons',
408 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
409 //html : this.triggerText
410 html: btn_text_select
416 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
424 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
426 html: btn_text_cancel
434 cls: 'roo-select2-search-field-input'
440 Roo.each(buttons.cn, function(c){
442 c.cls += ' btn-' + _this.size;
445 if (_this.disabled) {
452 style : 'display: contents',
457 cls: 'form-hidden-field'
461 cls: 'roo-select2-choices',
465 cls: 'roo-select2-search-field',
476 cls: 'roo-select2-container input-group roo-select2-container-multi',
482 // cls: 'typeahead typeahead-long dropdown-menu',
483 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
488 if(this.hasFeedback && !this.allowBlank){
492 cls: 'glyphicon form-control-feedback'
495 combobox.cn.push(feedback);
502 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
503 tooltip : 'This field is required'
505 if (Roo.bootstrap.version == 4) {
508 style : 'display:none'
511 if (align ==='left' && this.fieldLabel.length) {
513 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
520 cls : 'control-label col-form-label',
521 html : this.fieldLabel
533 var labelCfg = cfg.cn[1];
534 var contentCfg = cfg.cn[2];
537 if(this.indicatorpos == 'right'){
543 cls : 'control-label col-form-label',
547 html : this.fieldLabel
563 labelCfg = cfg.cn[0];
564 contentCfg = cfg.cn[1];
568 if(this.labelWidth > 12){
569 labelCfg.style = "width: " + this.labelWidth + 'px';
571 if(this.width * 1 > 0){
572 contentCfg.style = "width: " + this.width + 'px';
574 if(this.labelWidth < 13 && this.labelmd == 0){
575 this.labelmd = this.labelWidth;
578 if(this.labellg > 0){
579 labelCfg.cls += ' col-lg-' + this.labellg;
580 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
583 if(this.labelmd > 0){
584 labelCfg.cls += ' col-md-' + this.labelmd;
585 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
588 if(this.labelsm > 0){
589 labelCfg.cls += ' col-sm-' + this.labelsm;
590 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
593 if(this.labelxs > 0){
594 labelCfg.cls += ' col-xs-' + this.labelxs;
595 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
599 } else if ( this.fieldLabel.length) {
600 // Roo.log(" label");
605 //cls : 'input-group-addon',
606 html : this.fieldLabel
611 if(this.indicatorpos == 'right'){
615 //cls : 'input-group-addon',
616 html : this.fieldLabel
626 // Roo.log(" no label && no align");
633 ['xs','sm','md','lg'].map(function(size){
634 if (settings[size]) {
635 cfg.cls += ' col-' + size + '-' + settings[size];
643 _initEventsCalled : false,
646 initEvents: function()
648 if (this._initEventsCalled) { // as we call render... prevent looping...
651 this._initEventsCalled = true;
654 throw "can not find store for combo";
657 this.indicator = this.indicatorEl();
659 this.store = Roo.factory(this.store, Roo.data);
660 this.store.parent = this;
662 // if we are building from html. then this element is so complex, that we can not really
663 // use the rendered HTML.
664 // so we have to trash and replace the previous code.
665 if (Roo.XComponent.build_from_html) {
666 // remove this element....
667 var e = this.el.dom, k=0;
668 while (e ) { e = e.previousSibling; ++k;}
673 this.rendered = false;
675 this.render(this.parent().getChildContainer(true), k);
678 if(Roo.isIOS && this.useNativeIOS){
687 if(Roo.isTouch && this.mobileTouchView){
688 this.initTouchView();
693 this.initTickableEvents();
697 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
701 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
703 this.hiddenField.dom.value =
704 this.hiddenValue !== undefined ? this.hiddenValue :
705 this.value !== undefined ? this.value : '';
707 // prevent input submission
708 this.el.dom.removeAttribute('name');
709 this.hiddenField.dom.setAttribute('name', this.hiddenName);
714 // this.el.dom.setAttribute('autocomplete', 'off');
717 var cls = 'x-combo-list';
719 //this.list = new Roo.Layer({
720 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
726 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
727 _this.list.setWidth(lw);
730 this.list.on('mouseover', this.onViewOver, this);
731 this.list.on('mousemove', this.onViewMove, this);
732 this.list.on('scroll', this.onViewScroll, this);
735 this.list.swallowEvent('mousewheel');
736 this.assetHeight = 0;
739 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
740 this.assetHeight += this.header.getHeight();
743 this.innerList = this.list.createChild({cls:cls+'-inner'});
744 this.innerList.on('mouseover', this.onViewOver, this);
745 this.innerList.on('mousemove', this.onViewMove, this);
746 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
748 if(this.allowBlank && !this.pageSize && !this.disableClear){
749 this.footer = this.list.createChild({cls:cls+'-ft'});
750 this.pageTb = new Roo.Toolbar(this.footer);
754 this.footer = this.list.createChild({cls:cls+'-ft'});
755 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
756 {pageSize: this.pageSize});
760 if (this.pageTb && this.allowBlank && !this.disableClear) {
762 this.pageTb.add(new Roo.Toolbar.Fill(), {
763 cls: 'x-btn-icon x-btn-clear',
769 _this.onSelect(false, -1);
774 this.assetHeight += this.footer.getHeight();
779 this.tpl = Roo.bootstrap.version == 4 ?
780 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
781 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
784 this.view = new Roo.View(this.list, this.tpl, {
785 singleSelect:true, store: this.store, selectedClass: this.selectedClass
787 //this.view.wrapEl.setDisplayed(false);
788 this.view.on('click', this.onViewClick, this);
791 this.store.on('beforeload', this.onBeforeLoad, this);
792 this.store.on('load', this.onLoad, this);
793 this.store.on('loadexception', this.onLoadException, this);
796 this.resizer = new Roo.Resizable(this.list, {
797 pinned:true, handles:'se'
799 this.resizer.on('resize', function(r, w, h){
800 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
802 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
803 this.restrictHeight();
805 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
809 this.editable = true;
810 this.setEditable(false);
815 if (typeof(this.events.add.listeners) != 'undefined') {
817 this.addicon = this.wrap.createChild(
818 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
820 this.addicon.on('click', function(e) {
821 this.fireEvent('add', this);
824 if (typeof(this.events.edit.listeners) != 'undefined') {
826 this.editicon = this.wrap.createChild(
827 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
829 this.editicon.setStyle('margin-left', '40px');
831 this.editicon.on('click', function(e) {
833 // we fire even if inothing is selected..
834 this.fireEvent('edit', this, this.lastData );
840 this.keyNav = new Roo.KeyNav(this.inputEl(), {
842 this.inKeyMode = true;
846 "down" : function(e){
847 if(!this.isExpanded()){
848 this.onTriggerClick();
850 this.inKeyMode = true;
855 "enter" : function(e){
856 // this.onViewClick();
860 if(this.fireEvent("specialkey", this, e)){
861 this.onViewClick(false);
874 if(this.fireEvent("specialkey", this, e)){
875 this.onViewClick(false);
883 doRelay : function(foo, bar, hname){
884 if(hname == 'down' || this.scope.isExpanded()){
885 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
894 this.queryDelay = Math.max(this.queryDelay || 10,
895 this.mode == 'local' ? 10 : 250);
898 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
901 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
903 if(this.editable !== false){
904 this.inputEl().on("keyup", this.onKeyUp, this);
906 if(this.forceSelection){
907 this.inputEl().on('blur', this.doForce, this);
911 this.choices = this.el.select('ul.roo-select2-choices', true).first();
912 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
916 initTickableEvents: function()
922 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
924 this.hiddenField.dom.value =
925 this.hiddenValue !== undefined ? this.hiddenValue :
926 this.value !== undefined ? this.value : '';
928 // prevent input submission
929 this.el.dom.removeAttribute('name');
930 this.hiddenField.dom.setAttribute('name', this.hiddenName);
935 // this.list = this.el.select('ul.dropdown-menu',true).first();
937 this.choices = this.el.select('ul.roo-select2-choices', true).first();
938 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
939 if(this.triggerList){
940 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
943 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
944 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
946 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
947 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
949 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
950 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
952 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
953 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
954 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
957 this.cancelBtn.hide();
962 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
963 _this.list.setWidth(lw);
966 this.list.on('mouseover', this.onViewOver, this);
967 this.list.on('mousemove', this.onViewMove, this);
969 this.list.on('scroll', this.onViewScroll, this);
972 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
973 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
976 this.view = new Roo.View(this.list, this.tpl, {
981 selectedClass: this.selectedClass
984 //this.view.wrapEl.setDisplayed(false);
985 this.view.on('click', this.onViewClick, this);
989 this.store.on('beforeload', this.onBeforeLoad, this);
990 this.store.on('load', this.onLoad, this);
991 this.store.on('loadexception', this.onLoadException, this);
994 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
996 this.inKeyMode = true;
1000 "down" : function(e){
1001 this.inKeyMode = true;
1005 "enter" : function(e){
1006 if(this.fireEvent("specialkey", this, e)){
1007 this.onViewClick(false);
1013 "esc" : function(e){
1014 this.onTickableFooterButtonClick(e, false, false);
1017 "tab" : function(e){
1018 this.fireEvent("specialkey", this, e);
1020 this.onTickableFooterButtonClick(e, false, false);
1027 doRelay : function(e, fn, key){
1028 if(this.scope.isExpanded()){
1029 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1038 this.queryDelay = Math.max(this.queryDelay || 10,
1039 this.mode == 'local' ? 10 : 250);
1042 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1045 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1048 if(this.editable !== false){
1049 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1052 this.indicator = this.indicatorEl();
1055 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1056 this.indicator.hide();
1061 onDestroy : function(){
1063 this.view.setStore(null);
1064 this.view.el.removeAllListeners();
1065 this.view.el.remove();
1066 this.view.purgeListeners();
1069 this.list.dom.innerHTML = '';
1073 this.store.un('beforeload', this.onBeforeLoad, this);
1074 this.store.un('load', this.onLoad, this);
1075 this.store.un('loadexception', this.onLoadException, this);
1077 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1081 fireKey : function(e){
1082 if(e.isNavKeyPress() && !this.list.isVisible()){
1083 this.fireEvent("specialkey", this, e);
1088 onResize: function(w, h)
1092 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1094 // if(typeof w != 'number'){
1095 // // we do not handle it!?!?
1098 // var tw = this.trigger.getWidth();
1099 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1100 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1102 // this.inputEl().setWidth( this.adjustWidth('input', x));
1104 // //this.trigger.setStyle('left', x+'px');
1106 // if(this.list && this.listWidth === undefined){
1107 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1108 // this.list.setWidth(lw);
1109 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1117 * Allow or prevent the user from directly editing the field text. If false is passed,
1118 * the user will only be able to select from the items defined in the dropdown list. This method
1119 * is the runtime equivalent of setting the 'editable' config option at config time.
1120 * @param {Boolean} value True to allow the user to directly edit the field text
1122 setEditable : function(value){
1123 if(value == this.editable){
1126 this.editable = value;
1128 this.inputEl().dom.setAttribute('readOnly', true);
1129 this.inputEl().on('mousedown', this.onTriggerClick, this);
1130 this.inputEl().addClass('x-combo-noedit');
1132 this.inputEl().dom.removeAttribute('readOnly');
1133 this.inputEl().un('mousedown', this.onTriggerClick, this);
1134 this.inputEl().removeClass('x-combo-noedit');
1140 onBeforeLoad : function(combo,opts){
1145 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1147 this.restrictHeight();
1148 this.selectedIndex = -1;
1152 onLoad : function(){
1154 this.hasQuery = false;
1160 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1161 this.loading.hide();
1164 if(this.store.getCount() > 0){
1167 this.restrictHeight();
1168 if(this.lastQuery == this.allQuery){
1169 if(this.editable && !this.tickable){
1170 this.inputEl().dom.select();
1174 !this.selectByValue(this.value, true) &&
1177 !this.store.lastOptions ||
1178 typeof(this.store.lastOptions.add) == 'undefined' ||
1179 this.store.lastOptions.add != true
1182 this.select(0, true);
1188 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1189 this.taTask.delay(this.typeAheadDelay);
1193 this.onEmptyResults();
1199 onLoadException : function()
1201 this.hasQuery = false;
1203 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1204 this.loading.hide();
1207 if(this.tickable && this.editable){
1212 // only causes errors at present
1213 //Roo.log(this.store.reader.jsonData);
1214 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1216 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1222 onTypeAhead : function(){
1223 if(this.store.getCount() > 0){
1224 var r = this.store.getAt(0);
1225 var newValue = r.data[this.displayField];
1226 var len = newValue.length;
1227 var selStart = this.getRawValue().length;
1229 if(selStart != len){
1230 this.setRawValue(newValue);
1231 this.selectText(selStart, newValue.length);
1237 onSelect : function(record, index){
1239 if(this.fireEvent('beforeselect', this, record, index) !== false){
1241 this.setFromData(index > -1 ? record.data : false);
1244 this.fireEvent('select', this, record, index);
1249 * Returns the currently selected field value or empty string if no value is set.
1250 * @return {String} value The selected value
1252 getValue : function()
1254 if(Roo.isIOS && this.useNativeIOS){
1255 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1259 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1262 if(this.valueField){
1263 return typeof this.value != 'undefined' ? this.value : '';
1265 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1269 getRawValue : function()
1271 if(Roo.isIOS && this.useNativeIOS){
1272 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1275 var v = this.inputEl().getValue();
1281 * Clears any text/value currently set in the field
1283 clearValue : function(){
1285 if(this.hiddenField){
1286 this.hiddenField.dom.value = '';
1289 this.setRawValue('');
1290 this.lastSelectionText = '';
1291 this.lastData = false;
1293 var close = this.closeTriggerEl();
1304 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1305 * will be displayed in the field. If the value does not match the data value of an existing item,
1306 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1307 * Otherwise the field will be blank (although the value will still be set).
1308 * @param {String} value The value to match
1310 setValue : function(v)
1312 if(Roo.isIOS && this.useNativeIOS){
1313 this.setIOSValue(v);
1323 if(this.valueField){
1324 var r = this.findRecord(this.valueField, v);
1326 text = r.data[this.displayField];
1327 }else if(this.valueNotFoundText !== undefined){
1328 text = this.valueNotFoundText;
1331 this.lastSelectionText = text;
1332 if(this.hiddenField){
1333 this.hiddenField.dom.value = v;
1335 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1338 var close = this.closeTriggerEl();
1341 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1347 * @property {Object} the last set data for the element
1352 * Sets the value of the field based on a object which is related to the record format for the store.
1353 * @param {Object} value the value to set as. or false on reset?
1355 setFromData : function(o){
1362 var dv = ''; // display value
1363 var vv = ''; // value value..
1365 if (this.displayField) {
1366 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1368 // this is an error condition!!!
1369 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1372 if(this.valueField){
1373 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1376 var close = this.closeTriggerEl();
1379 if(dv.length || vv * 1 > 0){
1381 this.blockFocus=true;
1387 if(this.hiddenField){
1388 this.hiddenField.dom.value = vv;
1390 this.lastSelectionText = dv;
1391 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1395 // no hidden field.. - we store the value in 'value', but still display
1396 // display field!!!!
1397 this.lastSelectionText = dv;
1398 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1406 // overridden so that last data is reset..
1413 this.setValue(this.originalValue);
1414 //this.clearInvalid();
1415 this.lastData = false;
1417 this.view.clearSelections();
1423 findRecord : function(prop, value){
1425 if(this.store.getCount() > 0){
1426 this.store.each(function(r){
1427 if(r.data[prop] == value){
1439 // returns hidden if it's set..
1440 if (!this.rendered) {return ''};
1441 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1445 onViewMove : function(e, t){
1446 this.inKeyMode = false;
1450 onViewOver : function(e, t){
1451 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1454 var item = this.view.findItemFromChild(t);
1457 var index = this.view.indexOf(item);
1458 this.select(index, false);
1463 onViewClick : function(view, doFocus, el, e)
1465 var index = this.view.getSelectedIndexes()[0];
1467 var r = this.store.getAt(index);
1471 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1478 Roo.each(this.tickItems, function(v,k){
1480 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1482 _this.tickItems.splice(k, 1);
1484 if(typeof(e) == 'undefined' && view == false){
1485 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1497 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1498 this.tickItems.push(r.data);
1501 if(typeof(e) == 'undefined' && view == false){
1502 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1509 this.onSelect(r, index);
1511 if(doFocus !== false && !this.blockFocus){
1512 this.inputEl().focus();
1517 restrictHeight : function(){
1518 //this.innerList.dom.style.height = '';
1519 //var inner = this.innerList.dom;
1520 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1521 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1522 //this.list.beginUpdate();
1523 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1524 this.list.alignTo(this.inputEl(), this.listAlign);
1525 this.list.alignTo(this.inputEl(), this.listAlign);
1526 //this.list.endUpdate();
1530 onEmptyResults : function(){
1532 if(this.tickable && this.editable){
1533 this.hasFocus = false;
1534 this.restrictHeight();
1542 * Returns true if the dropdown list is expanded, else false.
1544 isExpanded : function(){
1545 return this.list.isVisible();
1549 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1550 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1551 * @param {String} value The data value of the item to select
1552 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1553 * selected item if it is not currently in view (defaults to true)
1554 * @return {Boolean} True if the value matched an item in the list, else false
1556 selectByValue : function(v, scrollIntoView){
1557 if(v !== undefined && v !== null){
1558 var r = this.findRecord(this.valueField || this.displayField, v);
1560 this.select(this.store.indexOf(r), scrollIntoView);
1568 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1569 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1570 * @param {Number} index The zero-based index of the list item to select
1571 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1572 * selected item if it is not currently in view (defaults to true)
1574 select : function(index, scrollIntoView){
1575 this.selectedIndex = index;
1576 this.view.select(index);
1577 if(scrollIntoView !== false){
1578 var el = this.view.getNode(index);
1580 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1583 this.list.scrollChildIntoView(el, false);
1589 selectNext : function(){
1590 var ct = this.store.getCount();
1592 if(this.selectedIndex == -1){
1594 }else if(this.selectedIndex < ct-1){
1595 this.select(this.selectedIndex+1);
1601 selectPrev : function(){
1602 var ct = this.store.getCount();
1604 if(this.selectedIndex == -1){
1606 }else if(this.selectedIndex != 0){
1607 this.select(this.selectedIndex-1);
1613 onKeyUp : function(e){
1614 if(this.editable !== false && !e.isSpecialKey()){
1615 this.lastKey = e.getKey();
1616 this.dqTask.delay(this.queryDelay);
1621 validateBlur : function(){
1622 return !this.list || !this.list.isVisible();
1626 initQuery : function(){
1628 var v = this.getRawValue();
1630 if(this.tickable && this.editable){
1631 v = this.tickableInputEl().getValue();
1638 doForce : function(){
1639 if(this.inputEl().dom.value.length > 0){
1640 this.inputEl().dom.value =
1641 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1647 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1648 * query allowing the query action to be canceled if needed.
1649 * @param {String} query The SQL query to execute
1650 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1651 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1652 * saved in the current store (defaults to false)
1654 doQuery : function(q, forceAll){
1656 if(q === undefined || q === null){
1665 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1670 forceAll = qe.forceAll;
1671 if(forceAll === true || (q.length >= this.minChars)){
1673 this.hasQuery = true;
1675 if(this.lastQuery != q || this.alwaysQuery){
1677 if(this.mode == 'local'){
1678 this.selectedIndex = -1;
1680 this.store.clearFilter();
1683 if(this.specialFilter){
1684 this.fireEvent('specialfilter', this);
1689 this.store.filter(this.displayField, q);
1692 this.store.fireEvent("datachanged", this.store);
1699 this.store.baseParams[this.queryParam] = q;
1701 var options = {params : this.getParams(q)};
1705 options.params.start = this.page * this.pageSize;
1708 this.store.load(options);
1711 * this code will make the page width larger, at the beginning, the list not align correctly,
1712 * we should expand the list on onLoad
1718 this.selectedIndex = -1;
1723 this.loadNext = false;
1727 getParams : function(q){
1729 //p[this.queryParam] = q;
1733 p.limit = this.pageSize;
1739 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1741 collapse : function(){
1742 if(!this.isExpanded()){
1748 this.hasFocus = false;
1752 this.cancelBtn.hide();
1753 this.trigger.show();
1756 this.tickableInputEl().dom.value = '';
1757 this.tickableInputEl().blur();
1762 Roo.get(document).un('mousedown', this.collapseIf, this);
1763 Roo.get(document).un('mousewheel', this.collapseIf, this);
1764 if (!this.editable) {
1765 Roo.get(document).un('keydown', this.listKeyPress, this);
1767 this.fireEvent('collapse', this);
1773 collapseIf : function(e){
1774 var in_combo = e.within(this.el);
1775 var in_list = e.within(this.list);
1776 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1778 if (in_combo || in_list || is_list) {
1779 //e.stopPropagation();
1784 this.onTickableFooterButtonClick(e, false, false);
1792 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1794 expand : function(){
1796 if(this.isExpanded() || !this.hasFocus){
1800 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1801 this.list.setWidth(lw);
1807 this.restrictHeight();
1811 this.tickItems = Roo.apply([], this.item);
1814 this.cancelBtn.show();
1815 this.trigger.hide();
1818 this.tickableInputEl().focus();
1823 Roo.get(document).on('mousedown', this.collapseIf, this);
1824 Roo.get(document).on('mousewheel', this.collapseIf, this);
1825 if (!this.editable) {
1826 Roo.get(document).on('keydown', this.listKeyPress, this);
1829 this.fireEvent('expand', this);
1833 // Implements the default empty TriggerField.onTriggerClick function
1834 onTriggerClick : function(e)
1836 Roo.log('trigger click');
1838 if(this.disabled || !this.triggerList){
1843 this.loadNext = false;
1845 if(this.isExpanded()){
1847 if (!this.blockFocus) {
1848 this.inputEl().focus();
1852 this.hasFocus = true;
1853 if(this.triggerAction == 'all') {
1854 this.doQuery(this.allQuery, true);
1856 this.doQuery(this.getRawValue());
1858 if (!this.blockFocus) {
1859 this.inputEl().focus();
1864 onTickableTriggerClick : function(e)
1871 this.loadNext = false;
1872 this.hasFocus = true;
1874 if(this.triggerAction == 'all') {
1875 this.doQuery(this.allQuery, true);
1877 this.doQuery(this.getRawValue());
1881 onSearchFieldClick : function(e)
1883 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1884 this.onTickableFooterButtonClick(e, false, false);
1888 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1893 this.loadNext = false;
1894 this.hasFocus = true;
1896 if(this.triggerAction == 'all') {
1897 this.doQuery(this.allQuery, true);
1899 this.doQuery(this.getRawValue());
1903 listKeyPress : function(e)
1905 //Roo.log('listkeypress');
1906 // scroll to first matching element based on key pres..
1907 if (e.isSpecialKey()) {
1910 var k = String.fromCharCode(e.getKey()).toUpperCase();
1913 var csel = this.view.getSelectedNodes();
1914 var cselitem = false;
1916 var ix = this.view.indexOf(csel[0]);
1917 cselitem = this.store.getAt(ix);
1918 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1924 this.store.each(function(v) {
1926 // start at existing selection.
1927 if (cselitem.id == v.id) {
1933 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1934 match = this.store.indexOf(v);
1940 if (match === false) {
1941 return true; // no more action?
1944 this.view.select(match);
1945 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1946 sn.scrollIntoView(sn.dom.parentNode, false);
1949 onViewScroll : function(e, t){
1951 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){
1955 this.hasQuery = true;
1957 this.loading = this.list.select('.loading', true).first();
1959 if(this.loading === null){
1960 this.list.createChild({
1962 cls: 'loading roo-select2-more-results roo-select2-active',
1963 html: 'Loading more results...'
1966 this.loading = this.list.select('.loading', true).first();
1968 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1970 this.loading.hide();
1973 this.loading.show();
1978 this.loadNext = true;
1980 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1985 addItem : function(o)
1987 var dv = ''; // display value
1989 if (this.displayField) {
1990 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1992 // this is an error condition!!!
1993 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
2000 var choice = this.choices.createChild({
2002 cls: 'roo-select2-search-choice',
2011 cls: 'roo-select2-search-choice-close fa fa-times',
2016 }, this.searchField);
2018 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2020 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2028 this.inputEl().dom.value = '';
2033 onRemoveItem : function(e, _self, o)
2037 this.lastItem = Roo.apply([], this.item);
2039 var index = this.item.indexOf(o.data) * 1;
2042 Roo.log('not this item?!');
2046 this.item.splice(index, 1);
2051 this.fireEvent('remove', this, e);
2057 syncValue : function()
2059 if(!this.item.length){
2066 Roo.each(this.item, function(i){
2067 if(_this.valueField){
2068 value.push(i[_this.valueField]);
2075 this.value = value.join(',');
2077 if(this.hiddenField){
2078 this.hiddenField.dom.value = this.value;
2081 this.store.fireEvent("datachanged", this.store);
2086 clearItem : function()
2094 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2102 if(this.tickable && !Roo.isTouch){
2103 this.view.refresh();
2107 inputEl: function ()
2109 if(Roo.isIOS && this.useNativeIOS){
2110 return this.el.select('select.roo-ios-select', true).first();
2113 if(Roo.isTouch && this.mobileTouchView){
2114 return this.el.select('input.form-control',true).first();
2118 return this.searchField;
2121 return this.el.select('input.form-control',true).first();
2124 onTickableFooterButtonClick : function(e, btn, el)
2128 this.lastItem = Roo.apply([], this.item);
2130 if(btn && btn.name == 'cancel'){
2131 this.tickItems = Roo.apply([], this.item);
2140 Roo.each(this.tickItems, function(o){
2148 validate : function()
2150 if(this.getVisibilityEl().hasClass('hidden')){
2154 var v = this.getRawValue();
2157 v = this.getValue();
2160 if(this.disabled || this.allowBlank || v.length){
2169 tickableInputEl : function()
2171 if(!this.tickable || !this.editable){
2172 return this.inputEl();
2175 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2179 getAutoCreateTouchView : function()
2184 cls: 'form-group' //input-group
2190 type : this.inputType,
2191 cls : 'form-control x-combo-noedit',
2192 autocomplete: 'new-password',
2193 placeholder : this.placeholder || '',
2198 input.name = this.name;
2202 input.cls += ' input-' + this.size;
2205 if (this.disabled) {
2206 input.disabled = true;
2210 cls : 'roo-combobox-wrap',
2217 inputblock.cls += ' input-group';
2219 inputblock.cn.unshift({
2221 cls : 'input-group-addon input-group-prepend input-group-text',
2226 if(this.removable && !this.multiple){
2227 inputblock.cls += ' roo-removable';
2229 inputblock.cn.push({
2232 cls : 'roo-combo-removable-btn close'
2236 if(this.hasFeedback && !this.allowBlank){
2238 inputblock.cls += ' has-feedback';
2240 inputblock.cn.push({
2242 cls: 'glyphicon form-control-feedback'
2249 inputblock.cls += (this.before) ? '' : ' input-group';
2251 inputblock.cn.push({
2253 cls : 'input-group-addon input-group-append input-group-text',
2259 var ibwrap = inputblock;
2264 cls: 'roo-select2-choices',
2268 cls: 'roo-select2-search-field',
2281 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2286 cls: 'form-hidden-field'
2292 if(!this.multiple && this.showToggleBtn){
2298 if (this.caret != false) {
2301 cls: 'fa fa-' + this.caret
2308 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2310 Roo.bootstrap.version == 3 ? caret : '',
2313 cls: 'combobox-clear',
2327 combobox.cls += ' roo-select2-container-multi';
2330 var required = this.allowBlank ? {
2332 style: 'display: none'
2335 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2336 tooltip : 'This field is required'
2339 var align = this.labelAlign || this.parentLabelAlign();
2341 if (align ==='left' && this.fieldLabel.length) {
2347 cls : 'control-label col-form-label',
2348 html : this.fieldLabel
2352 cls : 'roo-combobox-wrap ',
2359 var labelCfg = cfg.cn[1];
2360 var contentCfg = cfg.cn[2];
2363 if(this.indicatorpos == 'right'){
2368 cls : 'control-label col-form-label',
2372 html : this.fieldLabel
2378 cls : "roo-combobox-wrap ",
2386 labelCfg = cfg.cn[0];
2387 contentCfg = cfg.cn[1];
2392 if(this.labelWidth > 12){
2393 labelCfg.style = "width: " + this.labelWidth + 'px';
2396 if(this.labelWidth < 13 && this.labelmd == 0){
2397 this.labelmd = this.labelWidth;
2400 if(this.labellg > 0){
2401 labelCfg.cls += ' col-lg-' + this.labellg;
2402 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2405 if(this.labelmd > 0){
2406 labelCfg.cls += ' col-md-' + this.labelmd;
2407 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2410 if(this.labelsm > 0){
2411 labelCfg.cls += ' col-sm-' + this.labelsm;
2412 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2415 if(this.labelxs > 0){
2416 labelCfg.cls += ' col-xs-' + this.labelxs;
2417 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2421 } else if ( this.fieldLabel.length) {
2426 cls : 'control-label',
2427 html : this.fieldLabel
2438 if(this.indicatorpos == 'right'){
2442 cls : 'control-label',
2443 html : this.fieldLabel,
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','show']); }).defer(50);
2590 this.touchViewEl.addClass(['in','show']);
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','show']);
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