7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
20 * Create a new ComboBox.
21 * @param {Object} config Configuration options
23 Roo.bootstrap.ComboBox = function(config){
24 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
28 * Fires when the dropdown list is expanded
29 * @param {Roo.bootstrap.ComboBox} combo This combo box
34 * Fires when the dropdown list is collapsed
35 * @param {Roo.bootstrap.ComboBox} combo This combo box
40 * Fires before a list item is selected. Return false to cancel the selection.
41 * @param {Roo.bootstrap.ComboBox} combo This combo box
42 * @param {Roo.data.Record} record The data record returned from the underlying store
43 * @param {Number} index The index of the selected item in the dropdown list
45 'beforeselect' : true,
48 * Fires when a list item is selected
49 * @param {Roo.bootstrap.ComboBox} combo This combo box
50 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
51 * @param {Number} index The index of the selected item in the dropdown list
56 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
57 * The event object passed has these properties:
58 * @param {Roo.bootstrap.ComboBox} combo This combo box
59 * @param {String} query The query
60 * @param {Boolean} forceAll true to force "all" query
61 * @param {Boolean} cancel true to cancel the query
62 * @param {Object} e The query event object
67 * Fires when the 'add' icon is pressed (add a listener to enable add button)
68 * @param {Roo.bootstrap.ComboBox} combo This combo box
73 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
74 * @param {Roo.bootstrap.ComboBox} combo This combo box
75 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
80 * Fires when the remove value from the combobox array
81 * @param {Roo.bootstrap.ComboBox} combo This combo box
86 * Fires when the remove value from the combobox array
87 * @param {Roo.bootstrap.ComboBox} combo This combo box
91 * @event specialfilter
92 * Fires when specialfilter
93 * @param {Roo.bootstrap.ComboBox} combo This combo box
95 'specialfilter' : true,
98 * Fires when tick the element
99 * @param {Roo.bootstrap.ComboBox} combo This combo box
103 * @event touchviewdisplay
104 * Fires when touch view require special display (default is using displayField)
105 * @param {Roo.bootstrap.ComboBox} combo This combo box
106 * @param {Object} cfg set html .
108 'touchviewdisplay' : true
115 this.selectedIndex = -1;
116 if(this.mode == 'local'){
117 if(config.queryDelay === undefined){
118 this.queryDelay = 10;
120 if(config.minChars === undefined){
126 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
129 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
130 * rendering into an Roo.Editor, defaults to false)
133 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
134 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
137 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
140 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
141 * the dropdown list (defaults to undefined, with no header element)
145 * @cfg {String/Roo.Template} tpl The template to use to render the output
149 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
151 listWidth: undefined,
153 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
154 * mode = 'remote' or 'text' if mode = 'local')
156 displayField: undefined,
159 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
160 * mode = 'remote' or 'value' if mode = 'local').
161 * Note: use of a valueField requires the user make a selection
162 * in order for a value to be mapped.
164 valueField: undefined,
166 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
171 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
172 * field's data value (defaults to the underlying DOM element's name)
174 hiddenName: undefined,
176 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
180 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
182 selectedClass: 'active',
185 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
189 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
190 * anchor positions (defaults to 'tl-bl')
194 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
198 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
199 * query specified by the allQuery config option (defaults to 'query')
201 triggerAction: 'query',
203 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
204 * (defaults to 4, does not apply if editable = false)
208 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
209 * delay (typeAheadDelay) if it matches a known value (defaults to false)
213 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
214 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
218 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
219 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
223 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
224 * when editable = true (defaults to false)
228 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
232 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
233 * when mode = 'remote' (defaults to 'Loading...')
235 loadingText: 'Loading...',
237 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
241 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
245 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
246 * traditional select (defaults to true)
250 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
254 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
258 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
259 * listWidth has a higher value)
263 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
264 * allow the user to set arbitrary text into the field (defaults to false)
266 forceSelection:false,
268 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
269 * if typeAhead = true (defaults to 250)
271 typeAheadDelay : 250,
273 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
274 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
276 valueNotFoundText : undefined,
278 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
283 * @cfg {Boolean} disableClear Disable showing of clear button.
285 disableClear : false,
287 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
292 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
297 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
299 invalidClass : "has-warning",
302 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
304 validClass : "has-success",
307 * @cfg {Boolean} specialFilter (true|false) special filter default false
309 specialFilter : false,
312 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
314 mobileTouchView : true,
317 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
319 useNativeIOS : false,
333 btnPosition : 'right',
335 showToggleBtn : true,
337 emptyResultText: 'Empty',
338 triggerText : 'Select',
340 // element that contains real text value.. (when hidden is used..)
342 getAutoCreate : function()
348 * Render classic select for iso
351 if(Roo.isIOS && this.useNativeIOS){
352 cfg = this.getAutoCreateNativeIOS();
360 if(Roo.isTouch && this.mobileTouchView){
361 cfg = this.getAutoCreateTouchView();
369 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
370 if(this.name == 'info_year_invest_id_display_name'){
371 Roo.log('cfg.................................................');
378 * ComboBox with tickable selections
381 var align = this.labelAlign || this.parentLabelAlign();
384 cls : 'form-group roo-combobox-tickable' //input-group
387 var btn_text_select = '';
388 var btn_text_done = '';
389 var btn_text_cancel = '';
391 if (this.btn_text_show) {
392 btn_text_select = 'Select';
393 btn_text_done = 'Done';
394 btn_text_cancel = 'Cancel';
399 cls : 'tickable-buttons',
404 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
405 //html : this.triggerText
406 html: btn_text_select
412 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
420 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
422 html: btn_text_cancel
430 cls: 'roo-select2-search-field-input'
436 Roo.each(buttons.cn, function(c){
438 c.cls += ' btn-' + _this.size;
441 if (_this.disabled) {
452 cls: 'form-hidden-field'
456 cls: 'roo-select2-choices',
460 cls: 'roo-select2-search-field',
471 cls: 'roo-select2-container input-group roo-select2-container-multi',
476 // cls: 'typeahead typeahead-long dropdown-menu',
477 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
482 if(this.hasFeedback && !this.allowBlank){
486 cls: 'glyphicon form-control-feedback'
489 combobox.cn.push(feedback);
493 if (align ==='left' && this.fieldLabel.length) {
495 cfg.cls += ' roo-form-group-label-left';
500 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
501 tooltip : 'This field is required'
506 cls : 'control-label',
507 html : this.fieldLabel
519 var labelCfg = cfg.cn[1];
520 var contentCfg = cfg.cn[2];
523 if(this.indicatorpos == 'right'){
529 cls : 'control-label',
530 html : this.fieldLabel
534 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
535 tooltip : 'This field is required'
549 labelCfg = cfg.cn[0];
550 contentCfg = cfg.cn[2];
554 if(this.labelWidth > 12){
555 labelCfg.style = "width: " + this.labelWidth + 'px';
558 if(this.labelWidth < 13 && this.labelmd == 0){
559 this.labelmd = this.labelWidth;
562 if(this.labellg > 0){
563 labelCfg.cls += ' col-lg-' + this.labellg;
564 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
567 if(this.labelmd > 0){
568 labelCfg.cls += ' col-md-' + this.labelmd;
569 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
572 if(this.labelsm > 0){
573 labelCfg.cls += ' col-sm-' + this.labelsm;
574 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
577 if(this.labelxs > 0){
578 labelCfg.cls += ' col-xs-' + this.labelxs;
579 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
583 } else if ( this.fieldLabel.length) {
584 // Roo.log(" label");
588 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
589 tooltip : 'This field is required'
593 //cls : 'input-group-addon',
594 html : this.fieldLabel
602 if(this.indicatorpos == 'right'){
607 //cls : 'input-group-addon',
608 html : this.fieldLabel
612 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
613 tooltip : 'This field is required'
628 // Roo.log(" no label && no align");
635 ['xs','sm','md','lg'].map(function(size){
636 if (settings[size]) {
637 cfg.cls += ' col-' + size + '-' + settings[size];
645 _initEventsCalled : false,
648 initEvents: function()
650 if (this._initEventsCalled) { // as we call render... prevent looping...
653 this._initEventsCalled = true;
656 throw "can not find store for combo";
659 this.store = Roo.factory(this.store, Roo.data);
661 // if we are building from html. then this element is so complex, that we can not really
662 // use the rendered HTML.
663 // so we have to trash and replace the previous code.
664 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);
681 if(Roo.isIOS && this.useNativeIOS){
690 if(Roo.isTouch && this.mobileTouchView){
691 this.initTouchView();
696 this.initTickableEvents();
700 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
704 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
706 this.hiddenField.dom.value =
707 this.hiddenValue !== undefined ? this.hiddenValue :
708 this.value !== undefined ? this.value : '';
710 // prevent input submission
711 this.el.dom.removeAttribute('name');
712 this.hiddenField.dom.setAttribute('name', this.hiddenName);
717 // this.el.dom.setAttribute('autocomplete', 'off');
720 var cls = 'x-combo-list';
722 //this.list = new Roo.Layer({
723 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
729 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
730 _this.list.setWidth(lw);
733 this.list.on('mouseover', this.onViewOver, this);
734 this.list.on('mousemove', this.onViewMove, this);
736 this.list.on('scroll', this.onViewScroll, this);
739 this.list.swallowEvent('mousewheel');
740 this.assetHeight = 0;
743 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
744 this.assetHeight += this.header.getHeight();
747 this.innerList = this.list.createChild({cls:cls+'-inner'});
748 this.innerList.on('mouseover', this.onViewOver, this);
749 this.innerList.on('mousemove', this.onViewMove, this);
750 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
752 if(this.allowBlank && !this.pageSize && !this.disableClear){
753 this.footer = this.list.createChild({cls:cls+'-ft'});
754 this.pageTb = new Roo.Toolbar(this.footer);
758 this.footer = this.list.createChild({cls:cls+'-ft'});
759 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
760 {pageSize: this.pageSize});
764 if (this.pageTb && this.allowBlank && !this.disableClear) {
766 this.pageTb.add(new Roo.Toolbar.Fill(), {
767 cls: 'x-btn-icon x-btn-clear',
773 _this.onSelect(false, -1);
778 this.assetHeight += this.footer.getHeight();
783 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
786 this.view = new Roo.View(this.list, this.tpl, {
787 singleSelect:true, store: this.store, selectedClass: this.selectedClass
789 //this.view.wrapEl.setDisplayed(false);
790 this.view.on('click', this.onViewClick, this);
794 this.store.on('beforeload', this.onBeforeLoad, this);
795 this.store.on('load', this.onLoad, this);
796 this.store.on('loadexception', this.onLoadException, this);
799 this.resizer = new Roo.Resizable(this.list, {
800 pinned:true, handles:'se'
802 this.resizer.on('resize', function(r, w, h){
803 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
805 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
806 this.restrictHeight();
808 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
812 this.editable = true;
813 this.setEditable(false);
818 if (typeof(this.events.add.listeners) != 'undefined') {
820 this.addicon = this.wrap.createChild(
821 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
823 this.addicon.on('click', function(e) {
824 this.fireEvent('add', this);
827 if (typeof(this.events.edit.listeners) != 'undefined') {
829 this.editicon = this.wrap.createChild(
830 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
832 this.editicon.setStyle('margin-left', '40px');
834 this.editicon.on('click', function(e) {
836 // we fire even if inothing is selected..
837 this.fireEvent('edit', this, this.lastData );
843 this.keyNav = new Roo.KeyNav(this.inputEl(), {
845 this.inKeyMode = true;
849 "down" : function(e){
850 if(!this.isExpanded()){
851 this.onTriggerClick();
853 this.inKeyMode = true;
858 "enter" : function(e){
859 // this.onViewClick();
863 if(this.fireEvent("specialkey", this, e)){
864 this.onViewClick(false);
877 if(this.fireEvent("specialkey", this, e)){
878 this.onViewClick(false);
886 doRelay : function(foo, bar, hname){
887 if(hname == 'down' || this.scope.isExpanded()){
888 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
897 this.queryDelay = Math.max(this.queryDelay || 10,
898 this.mode == 'local' ? 10 : 250);
901 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
904 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
906 if(this.editable !== false){
907 this.inputEl().on("keyup", this.onKeyUp, this);
909 if(this.forceSelection){
910 this.inputEl().on('blur', this.doForce, this);
914 this.choices = this.el.select('ul.roo-select2-choices', true).first();
915 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
919 initTickableEvents: function()
925 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
927 this.hiddenField.dom.value =
928 this.hiddenValue !== undefined ? this.hiddenValue :
929 this.value !== undefined ? this.value : '';
931 // prevent input submission
932 this.el.dom.removeAttribute('name');
933 this.hiddenField.dom.setAttribute('name', this.hiddenName);
938 // this.list = this.el.select('ul.dropdown-menu',true).first();
940 this.choices = this.el.select('ul.roo-select2-choices', true).first();
941 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
942 if(this.triggerList){
943 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
946 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
947 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
949 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
950 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
952 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
953 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
955 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
956 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
957 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
960 this.cancelBtn.hide();
965 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
966 _this.list.setWidth(lw);
969 this.list.on('mouseover', this.onViewOver, this);
970 this.list.on('mousemove', this.onViewMove, this);
972 this.list.on('scroll', this.onViewScroll, this);
975 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
978 this.view = new Roo.View(this.list, this.tpl, {
979 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
982 //this.view.wrapEl.setDisplayed(false);
983 this.view.on('click', this.onViewClick, this);
987 this.store.on('beforeload', this.onBeforeLoad, this);
988 this.store.on('load', this.onLoad, this);
989 this.store.on('loadexception', this.onLoadException, this);
992 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
994 this.inKeyMode = true;
998 "down" : function(e){
999 this.inKeyMode = true;
1003 "enter" : function(e){
1004 if(this.fireEvent("specialkey", this, e)){
1005 this.onViewClick(false);
1011 "esc" : function(e){
1012 this.onTickableFooterButtonClick(e, false, false);
1015 "tab" : function(e){
1016 this.fireEvent("specialkey", this, e);
1018 this.onTickableFooterButtonClick(e, false, false);
1025 doRelay : function(e, fn, key){
1026 if(this.scope.isExpanded()){
1027 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1036 this.queryDelay = Math.max(this.queryDelay || 10,
1037 this.mode == 'local' ? 10 : 250);
1040 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1043 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1046 if(this.editable !== false){
1047 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1050 this.indicator = this.indicatorEl();
1053 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1054 this.indicator.hide();
1059 onDestroy : function(){
1061 this.view.setStore(null);
1062 this.view.el.removeAllListeners();
1063 this.view.el.remove();
1064 this.view.purgeListeners();
1067 this.list.dom.innerHTML = '';
1071 this.store.un('beforeload', this.onBeforeLoad, this);
1072 this.store.un('load', this.onLoad, this);
1073 this.store.un('loadexception', this.onLoadException, this);
1075 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1079 fireKey : function(e){
1080 if(e.isNavKeyPress() && !this.list.isVisible()){
1081 this.fireEvent("specialkey", this, e);
1086 onResize: function(w, h){
1087 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1089 // if(typeof w != 'number'){
1090 // // we do not handle it!?!?
1093 // var tw = this.trigger.getWidth();
1094 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1095 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1097 // this.inputEl().setWidth( this.adjustWidth('input', x));
1099 // //this.trigger.setStyle('left', x+'px');
1101 // if(this.list && this.listWidth === undefined){
1102 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1103 // this.list.setWidth(lw);
1104 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1112 * Allow or prevent the user from directly editing the field text. If false is passed,
1113 * the user will only be able to select from the items defined in the dropdown list. This method
1114 * is the runtime equivalent of setting the 'editable' config option at config time.
1115 * @param {Boolean} value True to allow the user to directly edit the field text
1117 setEditable : function(value){
1118 if(value == this.editable){
1121 this.editable = value;
1123 this.inputEl().dom.setAttribute('readOnly', true);
1124 this.inputEl().on('mousedown', this.onTriggerClick, this);
1125 this.inputEl().addClass('x-combo-noedit');
1127 this.inputEl().dom.setAttribute('readOnly', false);
1128 this.inputEl().un('mousedown', this.onTriggerClick, this);
1129 this.inputEl().removeClass('x-combo-noedit');
1135 onBeforeLoad : function(combo,opts){
1140 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1142 this.restrictHeight();
1143 this.selectedIndex = -1;
1147 onLoad : function(){
1149 this.hasQuery = false;
1155 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1156 this.loading.hide();
1159 if(this.store.getCount() > 0){
1161 this.restrictHeight();
1162 if(this.lastQuery == this.allQuery){
1163 if(this.editable && !this.tickable){
1164 this.inputEl().dom.select();
1168 !this.selectByValue(this.value, true) &&
1171 !this.store.lastOptions ||
1172 typeof(this.store.lastOptions.add) == 'undefined' ||
1173 this.store.lastOptions.add != true
1176 this.select(0, true);
1182 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1183 this.taTask.delay(this.typeAheadDelay);
1187 this.onEmptyResults();
1193 onLoadException : function()
1195 this.hasQuery = false;
1197 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1198 this.loading.hide();
1201 if(this.tickable && this.editable){
1206 // only causes errors at present
1207 //Roo.log(this.store.reader.jsonData);
1208 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1210 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1216 onTypeAhead : function(){
1217 if(this.store.getCount() > 0){
1218 var r = this.store.getAt(0);
1219 var newValue = r.data[this.displayField];
1220 var len = newValue.length;
1221 var selStart = this.getRawValue().length;
1223 if(selStart != len){
1224 this.setRawValue(newValue);
1225 this.selectText(selStart, newValue.length);
1231 onSelect : function(record, index){
1233 if(this.fireEvent('beforeselect', this, record, index) !== false){
1235 this.setFromData(index > -1 ? record.data : false);
1238 this.fireEvent('select', this, record, index);
1243 * Returns the currently selected field value or empty string if no value is set.
1244 * @return {String} value The selected value
1246 getValue : function()
1248 if(Roo.isIOS && this.useNativeIOS){
1249 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1253 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1256 if(this.valueField){
1257 return typeof this.value != 'undefined' ? this.value : '';
1259 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1263 getRawValue : function()
1265 if(Roo.isIOS && this.useNativeIOS){
1266 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1269 var v = this.inputEl().getValue();
1275 * Clears any text/value currently set in the field
1277 clearValue : function(){
1279 if(this.hiddenField){
1280 this.hiddenField.dom.value = '';
1283 this.setRawValue('');
1284 this.lastSelectionText = '';
1285 this.lastData = false;
1287 var close = this.closeTriggerEl();
1298 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1299 * will be displayed in the field. If the value does not match the data value of an existing item,
1300 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1301 * Otherwise the field will be blank (although the value will still be set).
1302 * @param {String} value The value to match
1304 setValue : function(v)
1306 if(Roo.isIOS && this.useNativeIOS){
1307 this.setIOSValue(v);
1317 if(this.valueField){
1318 var r = this.findRecord(this.valueField, v);
1320 text = r.data[this.displayField];
1321 }else if(this.valueNotFoundText !== undefined){
1322 text = this.valueNotFoundText;
1325 this.lastSelectionText = text;
1326 if(this.hiddenField){
1327 this.hiddenField.dom.value = v;
1329 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1332 var close = this.closeTriggerEl();
1335 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1341 * @property {Object} the last set data for the element
1346 * Sets the value of the field based on a object which is related to the record format for the store.
1347 * @param {Object} value the value to set as. or false on reset?
1349 setFromData : function(o){
1356 var dv = ''; // display value
1357 var vv = ''; // value value..
1359 if (this.displayField) {
1360 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1362 // this is an error condition!!!
1363 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1366 if(this.valueField){
1367 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1370 var close = this.closeTriggerEl();
1373 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1376 if(this.hiddenField){
1377 this.hiddenField.dom.value = vv;
1379 this.lastSelectionText = dv;
1380 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1384 // no hidden field.. - we store the value in 'value', but still display
1385 // display field!!!!
1386 this.lastSelectionText = dv;
1387 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1395 // overridden so that last data is reset..
1402 this.setValue(this.originalValue);
1403 //this.clearInvalid();
1404 this.lastData = false;
1406 this.view.clearSelections();
1412 findRecord : function(prop, value){
1414 if(this.store.getCount() > 0){
1415 this.store.each(function(r){
1416 if(r.data[prop] == value){
1428 // returns hidden if it's set..
1429 if (!this.rendered) {return ''};
1430 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1434 onViewMove : function(e, t){
1435 this.inKeyMode = false;
1439 onViewOver : function(e, t){
1440 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1443 var item = this.view.findItemFromChild(t);
1446 var index = this.view.indexOf(item);
1447 this.select(index, false);
1452 onViewClick : function(view, doFocus, el, e)
1454 var index = this.view.getSelectedIndexes()[0];
1456 var r = this.store.getAt(index);
1460 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1467 Roo.each(this.tickItems, function(v,k){
1469 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1471 _this.tickItems.splice(k, 1);
1473 if(typeof(e) == 'undefined' && view == false){
1474 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1486 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1487 this.tickItems.push(r.data);
1490 if(typeof(e) == 'undefined' && view == false){
1491 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1498 this.onSelect(r, index);
1500 if(doFocus !== false && !this.blockFocus){
1501 this.inputEl().focus();
1506 restrictHeight : function(){
1507 //this.innerList.dom.style.height = '';
1508 //var inner = this.innerList.dom;
1509 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1510 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1511 //this.list.beginUpdate();
1512 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1513 this.list.alignTo(this.inputEl(), this.listAlign);
1514 this.list.alignTo(this.inputEl(), this.listAlign);
1515 //this.list.endUpdate();
1519 onEmptyResults : function(){
1521 if(this.tickable && this.editable){
1522 this.restrictHeight();
1530 * Returns true if the dropdown list is expanded, else false.
1532 isExpanded : function(){
1533 return this.list.isVisible();
1537 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1538 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1539 * @param {String} value The data value of the item to select
1540 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1541 * selected item if it is not currently in view (defaults to true)
1542 * @return {Boolean} True if the value matched an item in the list, else false
1544 selectByValue : function(v, scrollIntoView){
1545 if(v !== undefined && v !== null){
1546 var r = this.findRecord(this.valueField || this.displayField, v);
1548 this.select(this.store.indexOf(r), scrollIntoView);
1556 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1557 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1558 * @param {Number} index The zero-based index of the list item to select
1559 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1560 * selected item if it is not currently in view (defaults to true)
1562 select : function(index, scrollIntoView){
1563 this.selectedIndex = index;
1564 this.view.select(index);
1565 if(scrollIntoView !== false){
1566 var el = this.view.getNode(index);
1568 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1571 this.list.scrollChildIntoView(el, false);
1577 selectNext : function(){
1578 var ct = this.store.getCount();
1580 if(this.selectedIndex == -1){
1582 }else if(this.selectedIndex < ct-1){
1583 this.select(this.selectedIndex+1);
1589 selectPrev : function(){
1590 var ct = this.store.getCount();
1592 if(this.selectedIndex == -1){
1594 }else if(this.selectedIndex != 0){
1595 this.select(this.selectedIndex-1);
1601 onKeyUp : function(e){
1602 if(this.editable !== false && !e.isSpecialKey()){
1603 this.lastKey = e.getKey();
1604 this.dqTask.delay(this.queryDelay);
1609 validateBlur : function(){
1610 return !this.list || !this.list.isVisible();
1614 initQuery : function(){
1616 var v = this.getRawValue();
1618 if(this.tickable && this.editable){
1619 v = this.tickableInputEl().getValue();
1626 doForce : function(){
1627 if(this.inputEl().dom.value.length > 0){
1628 this.inputEl().dom.value =
1629 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1635 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1636 * query allowing the query action to be canceled if needed.
1637 * @param {String} query The SQL query to execute
1638 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1639 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1640 * saved in the current store (defaults to false)
1642 doQuery : function(q, forceAll){
1644 if(q === undefined || q === null){
1653 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1658 forceAll = qe.forceAll;
1659 if(forceAll === true || (q.length >= this.minChars)){
1661 this.hasQuery = true;
1663 if(this.lastQuery != q || this.alwaysQuery){
1665 if(this.mode == 'local'){
1666 this.selectedIndex = -1;
1668 this.store.clearFilter();
1671 if(this.specialFilter){
1672 this.fireEvent('specialfilter', this);
1677 this.store.filter(this.displayField, q);
1680 this.store.fireEvent("datachanged", this.store);
1687 this.store.baseParams[this.queryParam] = q;
1689 var options = {params : this.getParams(q)};
1693 options.params.start = this.page * this.pageSize;
1696 this.store.load(options);
1699 * this code will make the page width larger, at the beginning, the list not align correctly,
1700 * we should expand the list on onLoad
1706 this.selectedIndex = -1;
1711 this.loadNext = false;
1715 getParams : function(q){
1717 //p[this.queryParam] = q;
1721 p.limit = this.pageSize;
1727 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1729 collapse : function(){
1730 if(!this.isExpanded()){
1736 this.hasFocus = false;
1740 this.cancelBtn.hide();
1741 this.trigger.show();
1744 this.tickableInputEl().dom.value = '';
1745 this.tickableInputEl().blur();
1750 Roo.get(document).un('mousedown', this.collapseIf, this);
1751 Roo.get(document).un('mousewheel', this.collapseIf, this);
1752 if (!this.editable) {
1753 Roo.get(document).un('keydown', this.listKeyPress, this);
1755 this.fireEvent('collapse', this);
1761 collapseIf : function(e){
1762 var in_combo = e.within(this.el);
1763 var in_list = e.within(this.list);
1764 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1766 if (in_combo || in_list || is_list) {
1767 //e.stopPropagation();
1772 this.onTickableFooterButtonClick(e, false, false);
1780 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1782 expand : function(){
1784 if(this.isExpanded() || !this.hasFocus){
1788 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1789 this.list.setWidth(lw);
1795 this.restrictHeight();
1799 this.tickItems = Roo.apply([], this.item);
1802 this.cancelBtn.show();
1803 this.trigger.hide();
1806 this.tickableInputEl().focus();
1811 Roo.get(document).on('mousedown', this.collapseIf, this);
1812 Roo.get(document).on('mousewheel', this.collapseIf, this);
1813 if (!this.editable) {
1814 Roo.get(document).on('keydown', this.listKeyPress, this);
1817 this.fireEvent('expand', this);
1821 // Implements the default empty TriggerField.onTriggerClick function
1822 onTriggerClick : function(e)
1824 Roo.log('trigger click');
1826 if(this.disabled || !this.triggerList){
1831 this.loadNext = false;
1833 if(this.isExpanded()){
1835 if (!this.blockFocus) {
1836 this.inputEl().focus();
1840 this.hasFocus = true;
1841 if(this.triggerAction == 'all') {
1842 this.doQuery(this.allQuery, true);
1844 this.doQuery(this.getRawValue());
1846 if (!this.blockFocus) {
1847 this.inputEl().focus();
1852 onTickableTriggerClick : function(e)
1859 this.loadNext = false;
1860 this.hasFocus = true;
1862 if(this.triggerAction == 'all') {
1863 this.doQuery(this.allQuery, true);
1865 this.doQuery(this.getRawValue());
1869 onSearchFieldClick : function(e)
1871 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1872 this.onTickableFooterButtonClick(e, false, false);
1876 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1881 this.loadNext = false;
1882 this.hasFocus = true;
1884 if(this.triggerAction == 'all') {
1885 this.doQuery(this.allQuery, true);
1887 this.doQuery(this.getRawValue());
1891 listKeyPress : function(e)
1893 //Roo.log('listkeypress');
1894 // scroll to first matching element based on key pres..
1895 if (e.isSpecialKey()) {
1898 var k = String.fromCharCode(e.getKey()).toUpperCase();
1901 var csel = this.view.getSelectedNodes();
1902 var cselitem = false;
1904 var ix = this.view.indexOf(csel[0]);
1905 cselitem = this.store.getAt(ix);
1906 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1912 this.store.each(function(v) {
1914 // start at existing selection.
1915 if (cselitem.id == v.id) {
1921 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1922 match = this.store.indexOf(v);
1928 if (match === false) {
1929 return true; // no more action?
1932 this.view.select(match);
1933 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1934 sn.scrollIntoView(sn.dom.parentNode, false);
1937 onViewScroll : function(e, t){
1939 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){
1943 this.hasQuery = true;
1945 this.loading = this.list.select('.loading', true).first();
1947 if(this.loading === null){
1948 this.list.createChild({
1950 cls: 'loading roo-select2-more-results roo-select2-active',
1951 html: 'Loading more results...'
1954 this.loading = this.list.select('.loading', true).first();
1956 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1958 this.loading.hide();
1961 this.loading.show();
1966 this.loadNext = true;
1968 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1973 addItem : function(o)
1975 var dv = ''; // display value
1977 if (this.displayField) {
1978 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1980 // this is an error condition!!!
1981 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1988 var choice = this.choices.createChild({
1990 cls: 'roo-select2-search-choice',
1999 cls: 'roo-select2-search-choice-close',
2004 }, this.searchField);
2006 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2008 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2016 this.inputEl().dom.value = '';
2021 onRemoveItem : function(e, _self, o)
2025 this.lastItem = Roo.apply([], this.item);
2027 var index = this.item.indexOf(o.data) * 1;
2030 Roo.log('not this item?!');
2034 this.item.splice(index, 1);
2039 this.fireEvent('remove', this, e);
2045 syncValue : function()
2047 if(!this.item.length){
2054 Roo.each(this.item, function(i){
2055 if(_this.valueField){
2056 value.push(i[_this.valueField]);
2063 this.value = value.join(',');
2065 if(this.hiddenField){
2066 this.hiddenField.dom.value = this.value;
2069 this.store.fireEvent("datachanged", this.store);
2074 clearItem : function()
2082 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2090 if(this.tickable && !Roo.isTouch){
2091 this.view.refresh();
2095 inputEl: function ()
2097 if(Roo.isIOS && this.useNativeIOS){
2098 return this.el.select('select.roo-ios-select', true).first();
2101 if(Roo.isTouch && this.mobileTouchView){
2102 return this.el.select('input.form-control',true).first();
2106 return this.searchField;
2109 return this.el.select('input.form-control',true).first();
2112 onTickableFooterButtonClick : function(e, btn, el)
2116 this.lastItem = Roo.apply([], this.item);
2118 if(btn && btn.name == 'cancel'){
2119 this.tickItems = Roo.apply([], this.item);
2128 Roo.each(this.tickItems, function(o){
2136 validate : function()
2138 var v = this.getRawValue();
2141 v = this.getValue();
2144 if(this.disabled || this.allowBlank || v.length){
2153 tickableInputEl : function()
2155 if(!this.tickable || !this.editable){
2156 return this.inputEl();
2159 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2163 getAutoCreateTouchView : function()
2168 cls: 'form-group' //input-group
2174 type : this.inputType,
2175 cls : 'form-control x-combo-noedit',
2176 autocomplete: 'new-password',
2177 placeholder : this.placeholder || '',
2182 input.name = this.name;
2186 input.cls += ' input-' + this.size;
2189 if (this.disabled) {
2190 input.disabled = true;
2201 inputblock.cls += ' input-group';
2203 inputblock.cn.unshift({
2205 cls : 'input-group-addon',
2210 if(this.removable && !this.multiple){
2211 inputblock.cls += ' roo-removable';
2213 inputblock.cn.push({
2216 cls : 'roo-combo-removable-btn close'
2220 if(this.hasFeedback && !this.allowBlank){
2222 inputblock.cls += ' has-feedback';
2224 inputblock.cn.push({
2226 cls: 'glyphicon form-control-feedback'
2233 inputblock.cls += (this.before) ? '' : ' input-group';
2235 inputblock.cn.push({
2237 cls : 'input-group-addon',
2248 cls: 'form-hidden-field'
2262 cls: 'form-hidden-field'
2266 cls: 'roo-select2-choices',
2270 cls: 'roo-select2-search-field',
2283 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2289 if(!this.multiple && this.showToggleBtn){
2296 if (this.caret != false) {
2299 cls: 'fa fa-' + this.caret
2306 cls : 'input-group-addon btn dropdown-toggle',
2311 cls: 'combobox-clear',
2325 combobox.cls += ' roo-select2-container-multi';
2328 var align = this.labelAlign || this.parentLabelAlign();
2330 if (align ==='left' && this.fieldLabel.length) {
2335 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2336 tooltip : 'This field is required'
2340 cls : 'control-label',
2341 html : this.fieldLabel
2352 var labelCfg = cfg.cn[1];
2353 var contentCfg = cfg.cn[2];
2356 if(this.indicatorpos == 'right'){
2360 cls : 'control-label',
2361 html : this.fieldLabel
2365 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2366 tooltip : 'This field is required'
2379 labelCfg = cfg.cn[0];
2380 contentCfg = cfg.cn[2];
2382 if(this.labelWidth > 12){
2383 labelCfg.style = "width: " + this.labelWidth + 'px';
2386 if(this.labelWidth < 13 && this.labelmd == 0){
2387 this.labelmd = this.labelWidth;
2390 if(this.labellg > 0){
2391 labelCfg.cls += ' col-lg-' + this.labellg;
2392 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2395 if(this.labelmd > 0){
2396 labelCfg.cls += ' col-md-' + this.labelmd;
2397 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2400 if(this.labelsm > 0){
2401 labelCfg.cls += ' col-sm-' + this.labelsm;
2402 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2405 if(this.labelxs > 0){
2406 labelCfg.cls += ' col-xs-' + this.labelxs;
2407 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2411 } else if ( this.fieldLabel.length) {
2415 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2416 tooltip : 'This field is required'
2420 cls : 'control-label',
2421 html : this.fieldLabel
2432 if(this.indicatorpos == 'right'){
2436 cls : 'control-label',
2437 html : this.fieldLabel
2441 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2442 tooltip : 'This field is required'
2459 var settings = this;
2461 ['xs','sm','md','lg'].map(function(size){
2462 if (settings[size]) {
2463 cfg.cls += ' col-' + size + '-' + settings[size];
2470 initTouchView : function()
2472 this.renderTouchView();
2474 this.touchViewEl.on('scroll', function(){
2475 this.el.dom.scrollTop = 0;
2478 this.originalValue = this.getValue();
2480 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2482 this.inputEl().on("click", this.showTouchView, this);
2483 if (this.triggerEl) {
2484 this.triggerEl.on("click", this.showTouchView, this);
2488 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2489 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2491 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2493 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2494 this.store.on('load', this.onTouchViewLoad, this);
2495 this.store.on('loadexception', this.onTouchViewLoadException, this);
2497 if(this.hiddenName){
2499 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2501 this.hiddenField.dom.value =
2502 this.hiddenValue !== undefined ? this.hiddenValue :
2503 this.value !== undefined ? this.value : '';
2505 this.el.dom.removeAttribute('name');
2506 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2510 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2511 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2514 if(this.removable && !this.multiple){
2515 var close = this.closeTriggerEl();
2517 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2518 close.on('click', this.removeBtnClick, this, close);
2522 * fix the bug in Safari iOS8
2524 this.inputEl().on("focus", function(e){
2525 document.activeElement.blur();
2533 renderTouchView : function()
2535 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2536 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2538 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2539 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2541 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2542 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2543 this.touchViewBodyEl.setStyle('overflow', 'auto');
2545 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2546 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2548 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2549 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2553 showTouchView : function()
2559 this.touchViewHeaderEl.hide();
2561 if(this.modalTitle.length){
2562 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2563 this.touchViewHeaderEl.show();
2566 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2567 this.touchViewEl.show();
2569 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2570 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2571 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2573 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2575 if(this.modalTitle.length){
2576 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2579 this.touchViewBodyEl.setHeight(bodyHeight);
2583 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2585 this.touchViewEl.addClass('in');
2588 this.doTouchViewQuery();
2592 hideTouchView : function()
2594 this.touchViewEl.removeClass('in');
2598 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2600 this.touchViewEl.setStyle('display', 'none');
2605 setTouchViewValue : function()
2612 Roo.each(this.tickItems, function(o){
2617 this.hideTouchView();
2620 doTouchViewQuery : function()
2629 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2633 if(!this.alwaysQuery || this.mode == 'local'){
2634 this.onTouchViewLoad();
2641 onTouchViewBeforeLoad : function(combo,opts)
2647 onTouchViewLoad : function()
2649 if(this.store.getCount() < 1){
2650 this.onTouchViewEmptyResults();
2654 this.clearTouchView();
2656 var rawValue = this.getRawValue();
2658 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2660 this.tickItems = [];
2662 this.store.data.each(function(d, rowIndex){
2663 var row = this.touchViewListGroup.createChild(template);
2665 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2666 row.addClass(d.data.cls);
2669 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2672 html : d.data[this.displayField]
2675 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2676 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2679 row.removeClass('selected');
2680 if(!this.multiple && this.valueField &&
2681 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2684 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2685 row.addClass('selected');
2688 if(this.multiple && this.valueField &&
2689 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2693 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2694 this.tickItems.push(d.data);
2697 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2701 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2703 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2705 if(this.modalTitle.length){
2706 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2709 var listHeight = this.touchViewListGroup.getHeight();
2713 if(firstChecked && listHeight > bodyHeight){
2714 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2719 onTouchViewLoadException : function()
2721 this.hideTouchView();
2724 onTouchViewEmptyResults : function()
2726 this.clearTouchView();
2728 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2730 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2734 clearTouchView : function()
2736 this.touchViewListGroup.dom.innerHTML = '';
2739 onTouchViewClick : function(e, el, o)
2744 var rowIndex = o.rowIndex;
2746 var r = this.store.getAt(rowIndex);
2748 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2751 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2752 c.dom.removeAttribute('checked');
2755 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2757 this.setFromData(r.data);
2759 var close = this.closeTriggerEl();
2765 this.hideTouchView();
2767 this.fireEvent('select', this, r, rowIndex);
2772 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2773 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2774 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2778 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2779 this.addItem(r.data);
2780 this.tickItems.push(r.data);
2784 getAutoCreateNativeIOS : function()
2787 cls: 'form-group' //input-group,
2792 cls : 'roo-ios-select'
2796 combobox.name = this.name;
2799 if (this.disabled) {
2800 combobox.disabled = true;
2803 var settings = this;
2805 ['xs','sm','md','lg'].map(function(size){
2806 if (settings[size]) {
2807 cfg.cls += ' col-' + size + '-' + settings[size];
2817 initIOSView : function()
2819 this.store.on('load', this.onIOSViewLoad, this);
2824 onIOSViewLoad : function()
2826 if(this.store.getCount() < 1){
2830 this.clearIOSView();
2832 if(this.allowBlank) {
2834 var default_text = '-- SELECT --';
2836 var opt = this.inputEl().createChild({
2843 o[this.valueField] = 0;
2844 o[this.displayField] = default_text;
2846 this.ios_options.push({
2853 this.store.data.each(function(d, rowIndex){
2857 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2858 html = d.data[this.displayField];
2863 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2864 value = d.data[this.valueField];
2873 if(this.value == d.data[this.valueField]){
2874 option['selected'] = true;
2877 var opt = this.inputEl().createChild(option);
2879 this.ios_options.push({
2886 this.inputEl().on('change', function(){
2887 this.fireEvent('select', this);
2892 clearIOSView: function()
2894 this.inputEl().dom.innerHTML = '';
2896 this.ios_options = [];
2899 setIOSValue: function(v)
2903 if(!this.ios_options){
2907 Roo.each(this.ios_options, function(opts){
2909 opts.el.dom.removeAttribute('selected');
2911 if(opts.data[this.valueField] != v){
2915 opts.el.dom.setAttribute('selected', true);
2921 * @cfg {Boolean} grow
2925 * @cfg {Number} growMin
2929 * @cfg {Number} growMax
2938 Roo.apply(Roo.bootstrap.ComboBox, {
2942 cls: 'modal-header',
2964 cls: 'list-group-item',
2968 cls: 'roo-combobox-list-group-item-value'
2972 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2986 listItemCheckbox : {
2988 cls: 'list-group-item',
2992 cls: 'roo-combobox-list-group-item-value'
2996 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3012 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3017 cls: 'modal-footer',
3025 cls: 'col-xs-6 text-left',
3028 cls: 'btn btn-danger roo-touch-view-cancel',
3034 cls: 'col-xs-6 text-right',
3037 cls: 'btn btn-success roo-touch-view-ok',
3048 Roo.apply(Roo.bootstrap.ComboBox, {
3050 touchViewTemplate : {
3052 cls: 'modal fade roo-combobox-touch-view',
3056 cls: 'modal-dialog',
3057 style : 'position:fixed', // we have to fix position....
3061 cls: 'modal-content',
3063 Roo.bootstrap.ComboBox.header,
3064 Roo.bootstrap.ComboBox.body,
3065 Roo.bootstrap.ComboBox.footer