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()
347 * Render classic select for iso
350 if(Roo.isIOS && this.useNativeIOS){
351 cfg = this.getAutoCreateNativeIOS();
359 if(Roo.isTouch && this.mobileTouchView){
360 cfg = this.getAutoCreateTouchView();
368 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
369 if(this.name == 'info_year_invest_id_display_name'){
370 Roo.log('cfg.................................................');
377 * ComboBox with tickable selections
380 var align = this.labelAlign || this.parentLabelAlign();
383 cls : 'form-group roo-combobox-tickable' //input-group
386 var btn_text_select = '';
387 var btn_text_done = '';
388 var btn_text_cancel = '';
390 if (this.btn_text_show) {
391 btn_text_select = 'Select';
392 btn_text_done = 'Done';
393 btn_text_cancel = 'Cancel';
398 cls : 'tickable-buttons',
403 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
404 //html : this.triggerText
405 html: btn_text_select
411 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
419 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
421 html: btn_text_cancel
429 cls: 'roo-select2-search-field-input'
435 Roo.each(buttons.cn, function(c){
437 c.cls += ' btn-' + _this.size;
440 if (_this.disabled) {
451 cls: 'form-hidden-field'
455 cls: 'roo-select2-choices',
459 cls: 'roo-select2-search-field',
470 cls: 'roo-select2-container input-group roo-select2-container-multi',
475 // cls: 'typeahead typeahead-long dropdown-menu',
476 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
481 if(this.hasFeedback && !this.allowBlank){
485 cls: 'glyphicon form-control-feedback'
488 combobox.cn.push(feedback);
492 if (align ==='left' && this.fieldLabel.length) {
494 cfg.cls += ' roo-form-group-label-left';
500 cls : 'control-label',
501 html : this.fieldLabel
505 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
506 tooltip : 'This field is required'
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
535 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
536 tooltip : 'This field is required'
547 labelCfg = cfg.cn[0];
548 contentCfg = cfg.cn[2];
552 if(this.labelWidth > 12){
553 labelCfg.style = "width: " + this.labelWidth + 'px';
556 if(this.labelWidth < 13 && this.labelmd == 0){
557 this.labelmd = this.labelWidth;
560 if(this.labellg > 0){
561 labelCfg.cls += ' col-lg-' + this.labellg;
562 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
565 if(this.labelmd > 0){
566 labelCfg.cls += ' col-md-' + this.labelmd;
567 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
570 if(this.labelsm > 0){
571 labelCfg.cls += ' col-sm-' + this.labelsm;
572 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
575 if(this.labelxs > 0){
576 labelCfg.cls += ' col-xs-' + this.labelxs;
577 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
581 } else if ( this.fieldLabel.length) {
582 // Roo.log(" label");
586 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
587 tooltip : 'This field is required'
591 //cls : 'input-group-addon',
592 html : this.fieldLabel
600 if(this.indicatorpos == 'right'){
605 //cls : 'input-group-addon',
606 html : this.fieldLabel
612 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
613 tooltip : 'This field is required'
624 // Roo.log(" no label && no align");
631 ['xs','sm','md','lg'].map(function(size){
632 if (settings[size]) {
633 cfg.cls += ' col-' + size + '-' + settings[size];
641 _initEventsCalled : false,
644 initEvents: function()
646 if (this._initEventsCalled) { // as we call render... prevent looping...
649 this._initEventsCalled = true;
652 throw "can not find store for combo";
655 this.store = Roo.factory(this.store, Roo.data);
657 // if we are building from html. then this element is so complex, that we can not really
658 // use the rendered HTML.
659 // so we have to trash and replace the previous code.
660 if (Roo.XComponent.build_from_html) {
662 // remove this element....
663 var e = this.el.dom, k=0;
664 while (e ) { e = e.previousSibling; ++k;}
669 this.rendered = false;
671 this.render(this.parent().getChildContainer(true), k);
677 if(Roo.isIOS && this.useNativeIOS){
686 if(Roo.isTouch && this.mobileTouchView){
687 this.initTouchView();
692 this.initTickableEvents();
696 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
700 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
702 this.hiddenField.dom.value =
703 this.hiddenValue !== undefined ? this.hiddenValue :
704 this.value !== undefined ? this.value : '';
706 // prevent input submission
707 this.el.dom.removeAttribute('name');
708 this.hiddenField.dom.setAttribute('name', this.hiddenName);
713 // this.el.dom.setAttribute('autocomplete', 'off');
716 var cls = 'x-combo-list';
718 //this.list = new Roo.Layer({
719 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
725 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
726 _this.list.setWidth(lw);
729 this.list.on('mouseover', this.onViewOver, this);
730 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 = '<li><a href="#">{' + this.displayField + '}</a></li>';
782 this.view = new Roo.View(this.list, this.tpl, {
783 singleSelect:true, store: this.store, selectedClass: this.selectedClass
785 //this.view.wrapEl.setDisplayed(false);
786 this.view.on('click', this.onViewClick, this);
790 this.store.on('beforeload', this.onBeforeLoad, this);
791 this.store.on('load', this.onLoad, this);
792 this.store.on('loadexception', this.onLoadException, this);
795 this.resizer = new Roo.Resizable(this.list, {
796 pinned:true, handles:'se'
798 this.resizer.on('resize', function(r, w, h){
799 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
801 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
802 this.restrictHeight();
804 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
808 this.editable = true;
809 this.setEditable(false);
814 if (typeof(this.events.add.listeners) != 'undefined') {
816 this.addicon = this.wrap.createChild(
817 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
819 this.addicon.on('click', function(e) {
820 this.fireEvent('add', this);
823 if (typeof(this.events.edit.listeners) != 'undefined') {
825 this.editicon = this.wrap.createChild(
826 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
828 this.editicon.setStyle('margin-left', '40px');
830 this.editicon.on('click', function(e) {
832 // we fire even if inothing is selected..
833 this.fireEvent('edit', this, this.lastData );
839 this.keyNav = new Roo.KeyNav(this.inputEl(), {
841 this.inKeyMode = true;
845 "down" : function(e){
846 if(!this.isExpanded()){
847 this.onTriggerClick();
849 this.inKeyMode = true;
854 "enter" : function(e){
855 // this.onViewClick();
859 if(this.fireEvent("specialkey", this, e)){
860 this.onViewClick(false);
873 if(this.fireEvent("specialkey", this, e)){
874 this.onViewClick(false);
882 doRelay : function(foo, bar, hname){
883 if(hname == 'down' || this.scope.isExpanded()){
884 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
893 this.queryDelay = Math.max(this.queryDelay || 10,
894 this.mode == 'local' ? 10 : 250);
897 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
900 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
902 if(this.editable !== false){
903 this.inputEl().on("keyup", this.onKeyUp, this);
905 if(this.forceSelection){
906 this.inputEl().on('blur', this.doForce, this);
910 this.choices = this.el.select('ul.roo-select2-choices', true).first();
911 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
915 initTickableEvents: function()
921 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
923 this.hiddenField.dom.value =
924 this.hiddenValue !== undefined ? this.hiddenValue :
925 this.value !== undefined ? this.value : '';
927 // prevent input submission
928 this.el.dom.removeAttribute('name');
929 this.hiddenField.dom.setAttribute('name', this.hiddenName);
934 // this.list = this.el.select('ul.dropdown-menu',true).first();
936 this.choices = this.el.select('ul.roo-select2-choices', true).first();
937 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
938 if(this.triggerList){
939 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
942 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
943 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
945 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
946 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
948 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
949 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
951 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
952 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
953 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
956 this.cancelBtn.hide();
961 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
962 _this.list.setWidth(lw);
965 this.list.on('mouseover', this.onViewOver, this);
966 this.list.on('mousemove', this.onViewMove, this);
968 this.list.on('scroll', this.onViewScroll, this);
971 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>';
974 this.view = new Roo.View(this.list, this.tpl, {
975 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
978 //this.view.wrapEl.setDisplayed(false);
979 this.view.on('click', this.onViewClick, this);
983 this.store.on('beforeload', this.onBeforeLoad, this);
984 this.store.on('load', this.onLoad, this);
985 this.store.on('loadexception', this.onLoadException, this);
988 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
990 this.inKeyMode = true;
994 "down" : function(e){
995 this.inKeyMode = true;
999 "enter" : function(e){
1000 if(this.fireEvent("specialkey", this, e)){
1001 this.onViewClick(false);
1007 "esc" : function(e){
1008 this.onTickableFooterButtonClick(e, false, false);
1011 "tab" : function(e){
1012 this.fireEvent("specialkey", this, e);
1014 this.onTickableFooterButtonClick(e, false, false);
1021 doRelay : function(e, fn, key){
1022 if(this.scope.isExpanded()){
1023 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1032 this.queryDelay = Math.max(this.queryDelay || 10,
1033 this.mode == 'local' ? 10 : 250);
1036 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1039 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1042 if(this.editable !== false){
1043 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1046 this.indicator = this.indicatorEl();
1049 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1050 this.indicator.hide();
1055 onDestroy : function(){
1057 this.view.setStore(null);
1058 this.view.el.removeAllListeners();
1059 this.view.el.remove();
1060 this.view.purgeListeners();
1063 this.list.dom.innerHTML = '';
1067 this.store.un('beforeload', this.onBeforeLoad, this);
1068 this.store.un('load', this.onLoad, this);
1069 this.store.un('loadexception', this.onLoadException, this);
1071 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1075 fireKey : function(e){
1076 if(e.isNavKeyPress() && !this.list.isVisible()){
1077 this.fireEvent("specialkey", this, e);
1082 onResize: function(w, h){
1083 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1085 // if(typeof w != 'number'){
1086 // // we do not handle it!?!?
1089 // var tw = this.trigger.getWidth();
1090 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1091 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1093 // this.inputEl().setWidth( this.adjustWidth('input', x));
1095 // //this.trigger.setStyle('left', x+'px');
1097 // if(this.list && this.listWidth === undefined){
1098 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1099 // this.list.setWidth(lw);
1100 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1108 * Allow or prevent the user from directly editing the field text. If false is passed,
1109 * the user will only be able to select from the items defined in the dropdown list. This method
1110 * is the runtime equivalent of setting the 'editable' config option at config time.
1111 * @param {Boolean} value True to allow the user to directly edit the field text
1113 setEditable : function(value){
1114 if(value == this.editable){
1117 this.editable = value;
1119 this.inputEl().dom.setAttribute('readOnly', true);
1120 this.inputEl().on('mousedown', this.onTriggerClick, this);
1121 this.inputEl().addClass('x-combo-noedit');
1123 this.inputEl().dom.setAttribute('readOnly', false);
1124 this.inputEl().un('mousedown', this.onTriggerClick, this);
1125 this.inputEl().removeClass('x-combo-noedit');
1131 onBeforeLoad : function(combo,opts){
1136 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1138 this.restrictHeight();
1139 this.selectedIndex = -1;
1143 onLoad : function(){
1145 this.hasQuery = false;
1151 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1152 this.loading.hide();
1155 if(this.store.getCount() > 0){
1157 this.restrictHeight();
1158 if(this.lastQuery == this.allQuery){
1159 if(this.editable && !this.tickable){
1160 this.inputEl().dom.select();
1164 !this.selectByValue(this.value, true) &&
1167 !this.store.lastOptions ||
1168 typeof(this.store.lastOptions.add) == 'undefined' ||
1169 this.store.lastOptions.add != true
1172 this.select(0, true);
1178 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1179 this.taTask.delay(this.typeAheadDelay);
1183 this.onEmptyResults();
1189 onLoadException : function()
1191 this.hasQuery = false;
1193 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1194 this.loading.hide();
1197 if(this.tickable && this.editable){
1202 // only causes errors at present
1203 //Roo.log(this.store.reader.jsonData);
1204 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1206 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1212 onTypeAhead : function(){
1213 if(this.store.getCount() > 0){
1214 var r = this.store.getAt(0);
1215 var newValue = r.data[this.displayField];
1216 var len = newValue.length;
1217 var selStart = this.getRawValue().length;
1219 if(selStart != len){
1220 this.setRawValue(newValue);
1221 this.selectText(selStart, newValue.length);
1227 onSelect : function(record, index){
1229 if(this.fireEvent('beforeselect', this, record, index) !== false){
1231 this.setFromData(index > -1 ? record.data : false);
1234 this.fireEvent('select', this, record, index);
1239 * Returns the currently selected field value or empty string if no value is set.
1240 * @return {String} value The selected value
1242 getValue : function()
1244 if(Roo.isIOS && this.useNativeIOS){
1245 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1249 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1252 if(this.valueField){
1253 return typeof this.value != 'undefined' ? this.value : '';
1255 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1259 getRawValue : function()
1261 if(Roo.isIOS && this.useNativeIOS){
1262 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1265 var v = this.inputEl().getValue();
1271 * Clears any text/value currently set in the field
1273 clearValue : function(){
1275 if(this.hiddenField){
1276 this.hiddenField.dom.value = '';
1279 this.setRawValue('');
1280 this.lastSelectionText = '';
1281 this.lastData = false;
1283 var close = this.closeTriggerEl();
1294 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1295 * will be displayed in the field. If the value does not match the data value of an existing item,
1296 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1297 * Otherwise the field will be blank (although the value will still be set).
1298 * @param {String} value The value to match
1300 setValue : function(v)
1302 if(Roo.isIOS && this.useNativeIOS){
1303 this.setIOSValue(v);
1313 if(this.valueField){
1314 var r = this.findRecord(this.valueField, v);
1316 text = r.data[this.displayField];
1317 }else if(this.valueNotFoundText !== undefined){
1318 text = this.valueNotFoundText;
1321 this.lastSelectionText = text;
1322 if(this.hiddenField){
1323 this.hiddenField.dom.value = v;
1325 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1328 var close = this.closeTriggerEl();
1331 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1337 * @property {Object} the last set data for the element
1342 * Sets the value of the field based on a object which is related to the record format for the store.
1343 * @param {Object} value the value to set as. or false on reset?
1345 setFromData : function(o){
1352 var dv = ''; // display value
1353 var vv = ''; // value value..
1355 if (this.displayField) {
1356 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1358 // this is an error condition!!!
1359 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1362 if(this.valueField){
1363 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1366 var close = this.closeTriggerEl();
1369 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1372 if(this.hiddenField){
1373 this.hiddenField.dom.value = vv;
1375 this.lastSelectionText = dv;
1376 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1380 // no hidden field.. - we store the value in 'value', but still display
1381 // display field!!!!
1382 this.lastSelectionText = dv;
1383 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1391 // overridden so that last data is reset..
1398 this.setValue(this.originalValue);
1399 //this.clearInvalid();
1400 this.lastData = false;
1402 this.view.clearSelections();
1408 findRecord : function(prop, value){
1410 if(this.store.getCount() > 0){
1411 this.store.each(function(r){
1412 if(r.data[prop] == value){
1424 // returns hidden if it's set..
1425 if (!this.rendered) {return ''};
1426 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1430 onViewMove : function(e, t){
1431 this.inKeyMode = false;
1435 onViewOver : function(e, t){
1436 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1439 var item = this.view.findItemFromChild(t);
1442 var index = this.view.indexOf(item);
1443 this.select(index, false);
1448 onViewClick : function(view, doFocus, el, e)
1450 var index = this.view.getSelectedIndexes()[0];
1452 var r = this.store.getAt(index);
1456 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1463 Roo.each(this.tickItems, function(v,k){
1465 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1467 _this.tickItems.splice(k, 1);
1469 if(typeof(e) == 'undefined' && view == false){
1470 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1482 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1483 this.tickItems.push(r.data);
1486 if(typeof(e) == 'undefined' && view == false){
1487 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1494 this.onSelect(r, index);
1496 if(doFocus !== false && !this.blockFocus){
1497 this.inputEl().focus();
1502 restrictHeight : function(){
1503 //this.innerList.dom.style.height = '';
1504 //var inner = this.innerList.dom;
1505 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1506 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1507 //this.list.beginUpdate();
1508 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1509 this.list.alignTo(this.inputEl(), this.listAlign);
1510 this.list.alignTo(this.inputEl(), this.listAlign);
1511 //this.list.endUpdate();
1515 onEmptyResults : function(){
1517 if(this.tickable && this.editable){
1518 this.restrictHeight();
1526 * Returns true if the dropdown list is expanded, else false.
1528 isExpanded : function(){
1529 return this.list.isVisible();
1533 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1534 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1535 * @param {String} value The data value of the item to select
1536 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1537 * selected item if it is not currently in view (defaults to true)
1538 * @return {Boolean} True if the value matched an item in the list, else false
1540 selectByValue : function(v, scrollIntoView){
1541 if(v !== undefined && v !== null){
1542 var r = this.findRecord(this.valueField || this.displayField, v);
1544 this.select(this.store.indexOf(r), scrollIntoView);
1552 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1553 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1554 * @param {Number} index The zero-based index of the list item to select
1555 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1556 * selected item if it is not currently in view (defaults to true)
1558 select : function(index, scrollIntoView){
1559 this.selectedIndex = index;
1560 this.view.select(index);
1561 if(scrollIntoView !== false){
1562 var el = this.view.getNode(index);
1564 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1567 this.list.scrollChildIntoView(el, false);
1573 selectNext : function(){
1574 var ct = this.store.getCount();
1576 if(this.selectedIndex == -1){
1578 }else if(this.selectedIndex < ct-1){
1579 this.select(this.selectedIndex+1);
1585 selectPrev : function(){
1586 var ct = this.store.getCount();
1588 if(this.selectedIndex == -1){
1590 }else if(this.selectedIndex != 0){
1591 this.select(this.selectedIndex-1);
1597 onKeyUp : function(e){
1598 if(this.editable !== false && !e.isSpecialKey()){
1599 this.lastKey = e.getKey();
1600 this.dqTask.delay(this.queryDelay);
1605 validateBlur : function(){
1606 return !this.list || !this.list.isVisible();
1610 initQuery : function(){
1612 var v = this.getRawValue();
1614 if(this.tickable && this.editable){
1615 v = this.tickableInputEl().getValue();
1622 doForce : function(){
1623 if(this.inputEl().dom.value.length > 0){
1624 this.inputEl().dom.value =
1625 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1631 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1632 * query allowing the query action to be canceled if needed.
1633 * @param {String} query The SQL query to execute
1634 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1635 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1636 * saved in the current store (defaults to false)
1638 doQuery : function(q, forceAll){
1640 if(q === undefined || q === null){
1649 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1654 forceAll = qe.forceAll;
1655 if(forceAll === true || (q.length >= this.minChars)){
1657 this.hasQuery = true;
1659 if(this.lastQuery != q || this.alwaysQuery){
1661 if(this.mode == 'local'){
1662 this.selectedIndex = -1;
1664 this.store.clearFilter();
1667 if(this.specialFilter){
1668 this.fireEvent('specialfilter', this);
1673 this.store.filter(this.displayField, q);
1676 this.store.fireEvent("datachanged", this.store);
1683 this.store.baseParams[this.queryParam] = q;
1685 var options = {params : this.getParams(q)};
1689 options.params.start = this.page * this.pageSize;
1692 this.store.load(options);
1695 * this code will make the page width larger, at the beginning, the list not align correctly,
1696 * we should expand the list on onLoad
1702 this.selectedIndex = -1;
1707 this.loadNext = false;
1711 getParams : function(q){
1713 //p[this.queryParam] = q;
1717 p.limit = this.pageSize;
1723 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1725 collapse : function(){
1726 if(!this.isExpanded()){
1732 this.hasFocus = false;
1736 this.cancelBtn.hide();
1737 this.trigger.show();
1740 this.tickableInputEl().dom.value = '';
1741 this.tickableInputEl().blur();
1746 Roo.get(document).un('mousedown', this.collapseIf, this);
1747 Roo.get(document).un('mousewheel', this.collapseIf, this);
1748 if (!this.editable) {
1749 Roo.get(document).un('keydown', this.listKeyPress, this);
1751 this.fireEvent('collapse', this);
1757 collapseIf : function(e){
1758 var in_combo = e.within(this.el);
1759 var in_list = e.within(this.list);
1760 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1762 if (in_combo || in_list || is_list) {
1763 //e.stopPropagation();
1768 this.onTickableFooterButtonClick(e, false, false);
1776 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1778 expand : function(){
1780 if(this.isExpanded() || !this.hasFocus){
1784 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1785 this.list.setWidth(lw);
1791 this.restrictHeight();
1795 this.tickItems = Roo.apply([], this.item);
1798 this.cancelBtn.show();
1799 this.trigger.hide();
1802 this.tickableInputEl().focus();
1807 Roo.get(document).on('mousedown', this.collapseIf, this);
1808 Roo.get(document).on('mousewheel', this.collapseIf, this);
1809 if (!this.editable) {
1810 Roo.get(document).on('keydown', this.listKeyPress, this);
1813 this.fireEvent('expand', this);
1817 // Implements the default empty TriggerField.onTriggerClick function
1818 onTriggerClick : function(e)
1820 Roo.log('trigger click');
1822 if(this.disabled || !this.triggerList){
1827 this.loadNext = false;
1829 if(this.isExpanded()){
1831 if (!this.blockFocus) {
1832 this.inputEl().focus();
1836 this.hasFocus = true;
1837 if(this.triggerAction == 'all') {
1838 this.doQuery(this.allQuery, true);
1840 this.doQuery(this.getRawValue());
1842 if (!this.blockFocus) {
1843 this.inputEl().focus();
1848 onTickableTriggerClick : function(e)
1855 this.loadNext = false;
1856 this.hasFocus = true;
1858 if(this.triggerAction == 'all') {
1859 this.doQuery(this.allQuery, true);
1861 this.doQuery(this.getRawValue());
1865 onSearchFieldClick : function(e)
1867 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1868 this.onTickableFooterButtonClick(e, false, false);
1872 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1877 this.loadNext = false;
1878 this.hasFocus = true;
1880 if(this.triggerAction == 'all') {
1881 this.doQuery(this.allQuery, true);
1883 this.doQuery(this.getRawValue());
1887 listKeyPress : function(e)
1889 //Roo.log('listkeypress');
1890 // scroll to first matching element based on key pres..
1891 if (e.isSpecialKey()) {
1894 var k = String.fromCharCode(e.getKey()).toUpperCase();
1897 var csel = this.view.getSelectedNodes();
1898 var cselitem = false;
1900 var ix = this.view.indexOf(csel[0]);
1901 cselitem = this.store.getAt(ix);
1902 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1908 this.store.each(function(v) {
1910 // start at existing selection.
1911 if (cselitem.id == v.id) {
1917 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1918 match = this.store.indexOf(v);
1924 if (match === false) {
1925 return true; // no more action?
1928 this.view.select(match);
1929 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1930 sn.scrollIntoView(sn.dom.parentNode, false);
1933 onViewScroll : function(e, t){
1935 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){
1939 this.hasQuery = true;
1941 this.loading = this.list.select('.loading', true).first();
1943 if(this.loading === null){
1944 this.list.createChild({
1946 cls: 'loading roo-select2-more-results roo-select2-active',
1947 html: 'Loading more results...'
1950 this.loading = this.list.select('.loading', true).first();
1952 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1954 this.loading.hide();
1957 this.loading.show();
1962 this.loadNext = true;
1964 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1969 addItem : function(o)
1971 var dv = ''; // display value
1973 if (this.displayField) {
1974 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1976 // this is an error condition!!!
1977 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1984 var choice = this.choices.createChild({
1986 cls: 'roo-select2-search-choice',
1995 cls: 'roo-select2-search-choice-close',
2000 }, this.searchField);
2002 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2004 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2012 this.inputEl().dom.value = '';
2017 onRemoveItem : function(e, _self, o)
2021 this.lastItem = Roo.apply([], this.item);
2023 var index = this.item.indexOf(o.data) * 1;
2026 Roo.log('not this item?!');
2030 this.item.splice(index, 1);
2035 this.fireEvent('remove', this, e);
2041 syncValue : function()
2043 if(!this.item.length){
2050 Roo.each(this.item, function(i){
2051 if(_this.valueField){
2052 value.push(i[_this.valueField]);
2059 this.value = value.join(',');
2061 if(this.hiddenField){
2062 this.hiddenField.dom.value = this.value;
2065 this.store.fireEvent("datachanged", this.store);
2070 clearItem : function()
2078 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2086 if(this.tickable && !Roo.isTouch){
2087 this.view.refresh();
2091 inputEl: function ()
2093 if(Roo.isIOS && this.useNativeIOS){
2094 return this.el.select('select.roo-ios-select', true).first();
2097 if(Roo.isTouch && this.mobileTouchView){
2098 return this.el.select('input.form-control',true).first();
2102 return this.searchField;
2105 return this.el.select('input.form-control',true).first();
2108 onTickableFooterButtonClick : function(e, btn, el)
2112 this.lastItem = Roo.apply([], this.item);
2114 if(btn && btn.name == 'cancel'){
2115 this.tickItems = Roo.apply([], this.item);
2124 Roo.each(this.tickItems, function(o){
2132 validate : function()
2134 var v = this.getRawValue();
2137 v = this.getValue();
2140 if(this.disabled || this.allowBlank || v.length){
2149 tickableInputEl : function()
2151 if(!this.tickable || !this.editable){
2152 return this.inputEl();
2155 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2159 getAutoCreateTouchView : function()
2164 cls: 'form-group' //input-group
2170 type : this.inputType,
2171 cls : 'form-control x-combo-noedit',
2172 autocomplete: 'new-password',
2173 placeholder : this.placeholder || '',
2178 input.name = this.name;
2182 input.cls += ' input-' + this.size;
2185 if (this.disabled) {
2186 input.disabled = true;
2197 inputblock.cls += ' input-group';
2199 inputblock.cn.unshift({
2201 cls : 'input-group-addon',
2206 if(this.removable && !this.multiple){
2207 inputblock.cls += ' roo-removable';
2209 inputblock.cn.push({
2212 cls : 'roo-combo-removable-btn close'
2216 if(this.hasFeedback && !this.allowBlank){
2218 inputblock.cls += ' has-feedback';
2220 inputblock.cn.push({
2222 cls: 'glyphicon form-control-feedback'
2229 inputblock.cls += (this.before) ? '' : ' input-group';
2231 inputblock.cn.push({
2233 cls : 'input-group-addon',
2244 cls: 'form-hidden-field'
2258 cls: 'form-hidden-field'
2262 cls: 'roo-select2-choices',
2266 cls: 'roo-select2-search-field',
2279 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2285 if(!this.multiple && this.showToggleBtn){
2292 if (this.caret != false) {
2295 cls: 'fa fa-' + this.caret
2302 cls : 'input-group-addon btn dropdown-toggle',
2307 cls: 'combobox-clear',
2321 combobox.cls += ' roo-select2-container-multi';
2324 var align = this.labelAlign || this.parentLabelAlign();
2326 if (align ==='left' && this.fieldLabel.length) {
2331 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2332 tooltip : 'This field is required'
2336 cls : 'control-label',
2337 html : this.fieldLabel
2348 var labelCfg = cfg.cn[1];
2349 var contentCfg = cfg.cn[2];
2352 if(this.indicatorpos == 'right'){
2356 cls : 'control-label',
2357 html : this.fieldLabel
2362 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2363 tooltip : 'This field is required'
2374 labelCfg = cfg.cn[0];
2375 contentCfg = cfg.cn[2];
2377 if(this.labelWidth > 12){
2378 labelCfg.style = "width: " + this.labelWidth + 'px';
2381 if(this.labelWidth < 13 && this.labelmd == 0){
2382 this.labelmd = this.labelWidth;
2385 if(this.labellg > 0){
2386 labelCfg.cls += ' col-lg-' + this.labellg;
2387 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2390 if(this.labelmd > 0){
2391 labelCfg.cls += ' col-md-' + this.labelmd;
2392 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2395 if(this.labelsm > 0){
2396 labelCfg.cls += ' col-sm-' + this.labelsm;
2397 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2400 if(this.labelxs > 0){
2401 labelCfg.cls += ' col-xs-' + this.labelxs;
2402 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2406 } else if ( this.fieldLabel.length) {
2410 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2411 tooltip : 'This field is required'
2415 cls : 'control-label',
2416 html : this.fieldLabel
2427 if(this.indicatorpos == 'right'){
2431 cls : 'control-label',
2432 html : this.fieldLabel
2437 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2438 tooltip : 'This field is required'
2453 var settings = this;
2455 ['xs','sm','md','lg'].map(function(size){
2456 if (settings[size]) {
2457 cfg.cls += ' col-' + size + '-' + settings[size];
2464 initTouchView : function()
2466 this.renderTouchView();
2468 this.touchViewEl.on('scroll', function(){
2469 this.el.dom.scrollTop = 0;
2472 this.originalValue = this.getValue();
2474 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2476 this.inputEl().on("click", this.showTouchView, this);
2477 if (this.triggerEl) {
2478 this.triggerEl.on("click", this.showTouchView, this);
2482 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2483 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2485 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2487 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2488 this.store.on('load', this.onTouchViewLoad, this);
2489 this.store.on('loadexception', this.onTouchViewLoadException, this);
2491 if(this.hiddenName){
2493 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2495 this.hiddenField.dom.value =
2496 this.hiddenValue !== undefined ? this.hiddenValue :
2497 this.value !== undefined ? this.value : '';
2499 this.el.dom.removeAttribute('name');
2500 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2504 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2505 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2508 if(this.removable && !this.multiple){
2509 var close = this.closeTriggerEl();
2511 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2512 close.on('click', this.removeBtnClick, this, close);
2516 * fix the bug in Safari iOS8
2518 this.inputEl().on("focus", function(e){
2519 document.activeElement.blur();
2527 renderTouchView : function()
2529 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2530 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2532 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2533 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2535 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2536 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2537 this.touchViewBodyEl.setStyle('overflow', 'auto');
2539 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2540 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2542 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2543 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2547 showTouchView : function()
2553 this.touchViewHeaderEl.hide();
2555 if(this.modalTitle.length){
2556 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2557 this.touchViewHeaderEl.show();
2560 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2561 this.touchViewEl.show();
2563 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2564 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2565 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2567 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2569 if(this.modalTitle.length){
2570 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2573 this.touchViewBodyEl.setHeight(bodyHeight);
2577 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2579 this.touchViewEl.addClass('in');
2582 this.doTouchViewQuery();
2586 hideTouchView : function()
2588 this.touchViewEl.removeClass('in');
2592 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2594 this.touchViewEl.setStyle('display', 'none');
2599 setTouchViewValue : function()
2606 Roo.each(this.tickItems, function(o){
2611 this.hideTouchView();
2614 doTouchViewQuery : function()
2623 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2627 if(!this.alwaysQuery || this.mode == 'local'){
2628 this.onTouchViewLoad();
2635 onTouchViewBeforeLoad : function(combo,opts)
2641 onTouchViewLoad : function()
2643 if(this.store.getCount() < 1){
2644 this.onTouchViewEmptyResults();
2648 this.clearTouchView();
2650 var rawValue = this.getRawValue();
2652 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2654 this.tickItems = [];
2656 this.store.data.each(function(d, rowIndex){
2657 var row = this.touchViewListGroup.createChild(template);
2659 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2660 row.addClass(d.data.cls);
2663 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2666 html : d.data[this.displayField]
2669 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2670 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2673 row.removeClass('selected');
2674 if(!this.multiple && this.valueField &&
2675 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2678 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2679 row.addClass('selected');
2682 if(this.multiple && this.valueField &&
2683 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2687 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2688 this.tickItems.push(d.data);
2691 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2695 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2697 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2699 if(this.modalTitle.length){
2700 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2703 var listHeight = this.touchViewListGroup.getHeight();
2707 if(firstChecked && listHeight > bodyHeight){
2708 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2713 onTouchViewLoadException : function()
2715 this.hideTouchView();
2718 onTouchViewEmptyResults : function()
2720 this.clearTouchView();
2722 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2724 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2728 clearTouchView : function()
2730 this.touchViewListGroup.dom.innerHTML = '';
2733 onTouchViewClick : function(e, el, o)
2738 var rowIndex = o.rowIndex;
2740 var r = this.store.getAt(rowIndex);
2742 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2745 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2746 c.dom.removeAttribute('checked');
2749 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2751 this.setFromData(r.data);
2753 var close = this.closeTriggerEl();
2759 this.hideTouchView();
2761 this.fireEvent('select', this, r, rowIndex);
2766 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2767 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2768 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2772 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2773 this.addItem(r.data);
2774 this.tickItems.push(r.data);
2778 getAutoCreateNativeIOS : function()
2781 cls: 'form-group' //input-group,
2786 cls : 'roo-ios-select'
2790 combobox.name = this.name;
2793 if (this.disabled) {
2794 combobox.disabled = true;
2797 var settings = this;
2799 ['xs','sm','md','lg'].map(function(size){
2800 if (settings[size]) {
2801 cfg.cls += ' col-' + size + '-' + settings[size];
2811 initIOSView : function()
2813 this.store.on('load', this.onIOSViewLoad, this);
2818 onIOSViewLoad : function()
2820 if(this.store.getCount() < 1){
2824 this.clearIOSView();
2826 if(this.allowBlank) {
2828 var default_text = '-- SELECT --';
2830 var opt = this.inputEl().createChild({
2837 o[this.valueField] = 0;
2838 o[this.displayField] = default_text;
2840 this.ios_options.push({
2847 this.store.data.each(function(d, rowIndex){
2851 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2852 html = d.data[this.displayField];
2857 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2858 value = d.data[this.valueField];
2867 if(this.value == d.data[this.valueField]){
2868 option['selected'] = true;
2871 var opt = this.inputEl().createChild(option);
2873 this.ios_options.push({
2880 this.inputEl().on('change', function(){
2881 this.fireEvent('select', this);
2886 clearIOSView: function()
2888 this.inputEl().dom.innerHTML = '';
2890 this.ios_options = [];
2893 setIOSValue: function(v)
2897 if(!this.ios_options){
2901 Roo.each(this.ios_options, function(opts){
2903 opts.el.dom.removeAttribute('selected');
2905 if(opts.data[this.valueField] != v){
2909 opts.el.dom.setAttribute('selected', true);
2915 * @cfg {Boolean} grow
2919 * @cfg {Number} growMin
2923 * @cfg {Number} growMax
2932 Roo.apply(Roo.bootstrap.ComboBox, {
2936 cls: 'modal-header',
2958 cls: 'list-group-item',
2962 cls: 'roo-combobox-list-group-item-value'
2966 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2980 listItemCheckbox : {
2982 cls: 'list-group-item',
2986 cls: 'roo-combobox-list-group-item-value'
2990 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3006 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3011 cls: 'modal-footer',
3019 cls: 'col-xs-6 text-left',
3022 cls: 'btn btn-danger roo-touch-view-cancel',
3028 cls: 'col-xs-6 text-right',
3031 cls: 'btn btn-success roo-touch-view-ok',
3042 Roo.apply(Roo.bootstrap.ComboBox, {
3044 touchViewTemplate : {
3046 cls: 'modal fade roo-combobox-touch-view',
3050 cls: 'modal-dialog',
3051 style : 'position:fixed', // we have to fix position....
3055 cls: 'modal-content',
3057 Roo.bootstrap.ComboBox.header,
3058 Roo.bootstrap.ComboBox.body,
3059 Roo.bootstrap.ComboBox.footer