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';
499 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
500 tooltip : 'This field is required'
505 cls : 'control-label',
506 html : this.fieldLabel
518 var labelCfg = cfg.cn[1];
519 var contentCfg = cfg.cn[2];
522 if(this.indicatorpos == 'right'){
528 cls : 'control-label',
529 html : this.fieldLabel
533 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
534 tooltip : 'This field is required'
548 labelCfg = cfg.cn[0];
549 contentCfg = cfg.cn[2];
553 if(this.labelWidth > 12){
554 labelCfg.style = "width: " + this.labelWidth + 'px';
557 if(this.labelWidth < 13 && this.labelmd == 0){
558 this.labelmd = this.labelWidth;
561 if(this.labellg > 0){
562 labelCfg.cls += ' col-lg-' + this.labellg;
563 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
566 if(this.labelmd > 0){
567 labelCfg.cls += ' col-md-' + this.labelmd;
568 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
571 if(this.labelsm > 0){
572 labelCfg.cls += ' col-sm-' + this.labelsm;
573 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
576 if(this.labelxs > 0){
577 labelCfg.cls += ' col-xs-' + this.labelxs;
578 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
582 } else if ( this.fieldLabel.length) {
583 // Roo.log(" label");
587 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
588 tooltip : 'This field is required'
592 //cls : 'input-group-addon',
593 html : this.fieldLabel
601 if(this.indicatorpos == 'right'){
606 //cls : 'input-group-addon',
607 html : this.fieldLabel
611 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
612 tooltip : 'This field is required'
627 // Roo.log(" no label && no align");
634 ['xs','sm','md','lg'].map(function(size){
635 if (settings[size]) {
636 cfg.cls += ' col-' + size + '-' + settings[size];
644 _initEventsCalled : false,
647 initEvents: function()
649 if (this._initEventsCalled) { // as we call render... prevent looping...
652 this._initEventsCalled = true;
655 throw "can not find store for combo";
658 this.store = Roo.factory(this.store, Roo.data);
660 // if we are building from html. then this element is so complex, that we can not really
661 // use the rendered HTML.
662 // so we have to trash and replace the previous code.
663 if (Roo.XComponent.build_from_html) {
665 // remove this element....
666 var e = this.el.dom, k=0;
667 while (e ) { e = e.previousSibling; ++k;}
672 this.rendered = false;
674 this.render(this.parent().getChildContainer(true), k);
680 if(Roo.isIOS && this.useNativeIOS){
689 if(Roo.isTouch && this.mobileTouchView){
690 this.initTouchView();
695 this.initTickableEvents();
699 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
703 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
705 this.hiddenField.dom.value =
706 this.hiddenValue !== undefined ? this.hiddenValue :
707 this.value !== undefined ? this.value : '';
709 // prevent input submission
710 this.el.dom.removeAttribute('name');
711 this.hiddenField.dom.setAttribute('name', this.hiddenName);
716 // this.el.dom.setAttribute('autocomplete', 'off');
719 var cls = 'x-combo-list';
721 //this.list = new Roo.Layer({
722 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
728 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
729 _this.list.setWidth(lw);
732 this.list.on('mouseover', this.onViewOver, this);
733 this.list.on('mousemove', this.onViewMove, this);
735 this.list.on('scroll', this.onViewScroll, this);
738 this.list.swallowEvent('mousewheel');
739 this.assetHeight = 0;
742 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
743 this.assetHeight += this.header.getHeight();
746 this.innerList = this.list.createChild({cls:cls+'-inner'});
747 this.innerList.on('mouseover', this.onViewOver, this);
748 this.innerList.on('mousemove', this.onViewMove, this);
749 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
751 if(this.allowBlank && !this.pageSize && !this.disableClear){
752 this.footer = this.list.createChild({cls:cls+'-ft'});
753 this.pageTb = new Roo.Toolbar(this.footer);
757 this.footer = this.list.createChild({cls:cls+'-ft'});
758 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
759 {pageSize: this.pageSize});
763 if (this.pageTb && this.allowBlank && !this.disableClear) {
765 this.pageTb.add(new Roo.Toolbar.Fill(), {
766 cls: 'x-btn-icon x-btn-clear',
772 _this.onSelect(false, -1);
777 this.assetHeight += this.footer.getHeight();
782 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
785 this.view = new Roo.View(this.list, this.tpl, {
786 singleSelect:true, store: this.store, selectedClass: this.selectedClass
788 //this.view.wrapEl.setDisplayed(false);
789 this.view.on('click', this.onViewClick, this);
793 this.store.on('beforeload', this.onBeforeLoad, this);
794 this.store.on('load', this.onLoad, this);
795 this.store.on('loadexception', this.onLoadException, this);
798 this.resizer = new Roo.Resizable(this.list, {
799 pinned:true, handles:'se'
801 this.resizer.on('resize', function(r, w, h){
802 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
804 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
805 this.restrictHeight();
807 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
811 this.editable = true;
812 this.setEditable(false);
817 if (typeof(this.events.add.listeners) != 'undefined') {
819 this.addicon = this.wrap.createChild(
820 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
822 this.addicon.on('click', function(e) {
823 this.fireEvent('add', this);
826 if (typeof(this.events.edit.listeners) != 'undefined') {
828 this.editicon = this.wrap.createChild(
829 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
831 this.editicon.setStyle('margin-left', '40px');
833 this.editicon.on('click', function(e) {
835 // we fire even if inothing is selected..
836 this.fireEvent('edit', this, this.lastData );
842 this.keyNav = new Roo.KeyNav(this.inputEl(), {
844 this.inKeyMode = true;
848 "down" : function(e){
849 if(!this.isExpanded()){
850 this.onTriggerClick();
852 this.inKeyMode = true;
857 "enter" : function(e){
858 // this.onViewClick();
862 if(this.fireEvent("specialkey", this, e)){
863 this.onViewClick(false);
876 if(this.fireEvent("specialkey", this, e)){
877 this.onViewClick(false);
885 doRelay : function(foo, bar, hname){
886 if(hname == 'down' || this.scope.isExpanded()){
887 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
896 this.queryDelay = Math.max(this.queryDelay || 10,
897 this.mode == 'local' ? 10 : 250);
900 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
903 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
905 if(this.editable !== false){
906 this.inputEl().on("keyup", this.onKeyUp, this);
908 if(this.forceSelection){
909 this.inputEl().on('blur', this.doForce, this);
913 this.choices = this.el.select('ul.roo-select2-choices', true).first();
914 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
918 initTickableEvents: function()
924 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
926 this.hiddenField.dom.value =
927 this.hiddenValue !== undefined ? this.hiddenValue :
928 this.value !== undefined ? this.value : '';
930 // prevent input submission
931 this.el.dom.removeAttribute('name');
932 this.hiddenField.dom.setAttribute('name', this.hiddenName);
937 // this.list = this.el.select('ul.dropdown-menu',true).first();
939 this.choices = this.el.select('ul.roo-select2-choices', true).first();
940 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
941 if(this.triggerList){
942 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
945 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
946 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
948 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
949 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
951 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
952 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
954 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
955 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
956 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
959 this.cancelBtn.hide();
964 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
965 _this.list.setWidth(lw);
968 this.list.on('mouseover', this.onViewOver, this);
969 this.list.on('mousemove', this.onViewMove, this);
971 this.list.on('scroll', this.onViewScroll, this);
974 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>';
977 this.view = new Roo.View(this.list, this.tpl, {
978 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
981 //this.view.wrapEl.setDisplayed(false);
982 this.view.on('click', this.onViewClick, this);
986 this.store.on('beforeload', this.onBeforeLoad, this);
987 this.store.on('load', this.onLoad, this);
988 this.store.on('loadexception', this.onLoadException, this);
991 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
993 this.inKeyMode = true;
997 "down" : function(e){
998 this.inKeyMode = true;
1002 "enter" : function(e){
1003 if(this.fireEvent("specialkey", this, e)){
1004 this.onViewClick(false);
1010 "esc" : function(e){
1011 this.onTickableFooterButtonClick(e, false, false);
1014 "tab" : function(e){
1015 this.fireEvent("specialkey", this, e);
1017 this.onTickableFooterButtonClick(e, false, false);
1024 doRelay : function(e, fn, key){
1025 if(this.scope.isExpanded()){
1026 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1035 this.queryDelay = Math.max(this.queryDelay || 10,
1036 this.mode == 'local' ? 10 : 250);
1039 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1042 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1045 if(this.editable !== false){
1046 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1049 this.indicator = this.indicatorEl();
1052 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1053 this.indicator.hide();
1058 onDestroy : function(){
1060 this.view.setStore(null);
1061 this.view.el.removeAllListeners();
1062 this.view.el.remove();
1063 this.view.purgeListeners();
1066 this.list.dom.innerHTML = '';
1070 this.store.un('beforeload', this.onBeforeLoad, this);
1071 this.store.un('load', this.onLoad, this);
1072 this.store.un('loadexception', this.onLoadException, this);
1074 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1078 fireKey : function(e){
1079 if(e.isNavKeyPress() && !this.list.isVisible()){
1080 this.fireEvent("specialkey", this, e);
1085 onResize: function(w, h){
1086 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1088 // if(typeof w != 'number'){
1089 // // we do not handle it!?!?
1092 // var tw = this.trigger.getWidth();
1093 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1094 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1096 // this.inputEl().setWidth( this.adjustWidth('input', x));
1098 // //this.trigger.setStyle('left', x+'px');
1100 // if(this.list && this.listWidth === undefined){
1101 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1102 // this.list.setWidth(lw);
1103 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1111 * Allow or prevent the user from directly editing the field text. If false is passed,
1112 * the user will only be able to select from the items defined in the dropdown list. This method
1113 * is the runtime equivalent of setting the 'editable' config option at config time.
1114 * @param {Boolean} value True to allow the user to directly edit the field text
1116 setEditable : function(value){
1117 if(value == this.editable){
1120 this.editable = value;
1122 this.inputEl().dom.setAttribute('readOnly', true);
1123 this.inputEl().on('mousedown', this.onTriggerClick, this);
1124 this.inputEl().addClass('x-combo-noedit');
1126 this.inputEl().dom.setAttribute('readOnly', false);
1127 this.inputEl().un('mousedown', this.onTriggerClick, this);
1128 this.inputEl().removeClass('x-combo-noedit');
1134 onBeforeLoad : function(combo,opts){
1139 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1141 this.restrictHeight();
1142 this.selectedIndex = -1;
1146 onLoad : function(){
1148 this.hasQuery = false;
1154 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1155 this.loading.hide();
1158 if(this.store.getCount() > 0){
1160 this.restrictHeight();
1161 if(this.lastQuery == this.allQuery){
1162 if(this.editable && !this.tickable){
1163 this.inputEl().dom.select();
1167 !this.selectByValue(this.value, true) &&
1170 !this.store.lastOptions ||
1171 typeof(this.store.lastOptions.add) == 'undefined' ||
1172 this.store.lastOptions.add != true
1175 this.select(0, true);
1181 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1182 this.taTask.delay(this.typeAheadDelay);
1186 this.onEmptyResults();
1192 onLoadException : function()
1194 this.hasQuery = false;
1196 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1197 this.loading.hide();
1200 if(this.tickable && this.editable){
1205 // only causes errors at present
1206 //Roo.log(this.store.reader.jsonData);
1207 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1209 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1215 onTypeAhead : function(){
1216 if(this.store.getCount() > 0){
1217 var r = this.store.getAt(0);
1218 var newValue = r.data[this.displayField];
1219 var len = newValue.length;
1220 var selStart = this.getRawValue().length;
1222 if(selStart != len){
1223 this.setRawValue(newValue);
1224 this.selectText(selStart, newValue.length);
1230 onSelect : function(record, index){
1232 if(this.fireEvent('beforeselect', this, record, index) !== false){
1234 this.setFromData(index > -1 ? record.data : false);
1237 this.fireEvent('select', this, record, index);
1242 * Returns the currently selected field value or empty string if no value is set.
1243 * @return {String} value The selected value
1245 getValue : function()
1247 if(Roo.isIOS && this.useNativeIOS){
1248 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1252 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1255 if(this.valueField){
1256 return typeof this.value != 'undefined' ? this.value : '';
1258 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1262 getRawValue : function()
1264 if(Roo.isIOS && this.useNativeIOS){
1265 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1268 var v = this.inputEl().getValue();
1274 * Clears any text/value currently set in the field
1276 clearValue : function(){
1278 if(this.hiddenField){
1279 this.hiddenField.dom.value = '';
1282 this.setRawValue('');
1283 this.lastSelectionText = '';
1284 this.lastData = false;
1286 var close = this.closeTriggerEl();
1297 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1298 * will be displayed in the field. If the value does not match the data value of an existing item,
1299 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1300 * Otherwise the field will be blank (although the value will still be set).
1301 * @param {String} value The value to match
1303 setValue : function(v)
1305 if(Roo.isIOS && this.useNativeIOS){
1306 this.setIOSValue(v);
1316 if(this.valueField){
1317 var r = this.findRecord(this.valueField, v);
1319 text = r.data[this.displayField];
1320 }else if(this.valueNotFoundText !== undefined){
1321 text = this.valueNotFoundText;
1324 this.lastSelectionText = text;
1325 if(this.hiddenField){
1326 this.hiddenField.dom.value = v;
1328 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1331 var close = this.closeTriggerEl();
1334 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1340 * @property {Object} the last set data for the element
1345 * Sets the value of the field based on a object which is related to the record format for the store.
1346 * @param {Object} value the value to set as. or false on reset?
1348 setFromData : function(o){
1355 var dv = ''; // display value
1356 var vv = ''; // value value..
1358 if (this.displayField) {
1359 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1361 // this is an error condition!!!
1362 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1365 if(this.valueField){
1366 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1369 var close = this.closeTriggerEl();
1372 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1375 if(this.hiddenField){
1376 this.hiddenField.dom.value = vv;
1378 this.lastSelectionText = dv;
1379 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1383 // no hidden field.. - we store the value in 'value', but still display
1384 // display field!!!!
1385 this.lastSelectionText = dv;
1386 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1394 // overridden so that last data is reset..
1401 this.setValue(this.originalValue);
1402 //this.clearInvalid();
1403 this.lastData = false;
1405 this.view.clearSelections();
1411 findRecord : function(prop, value){
1413 if(this.store.getCount() > 0){
1414 this.store.each(function(r){
1415 if(r.data[prop] == value){
1427 // returns hidden if it's set..
1428 if (!this.rendered) {return ''};
1429 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1433 onViewMove : function(e, t){
1434 this.inKeyMode = false;
1438 onViewOver : function(e, t){
1439 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1442 var item = this.view.findItemFromChild(t);
1445 var index = this.view.indexOf(item);
1446 this.select(index, false);
1451 onViewClick : function(view, doFocus, el, e)
1453 var index = this.view.getSelectedIndexes()[0];
1455 var r = this.store.getAt(index);
1459 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1466 Roo.each(this.tickItems, function(v,k){
1468 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1470 _this.tickItems.splice(k, 1);
1472 if(typeof(e) == 'undefined' && view == false){
1473 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1485 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1486 this.tickItems.push(r.data);
1489 if(typeof(e) == 'undefined' && view == false){
1490 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1497 this.onSelect(r, index);
1499 if(doFocus !== false && !this.blockFocus){
1500 this.inputEl().focus();
1505 restrictHeight : function(){
1506 //this.innerList.dom.style.height = '';
1507 //var inner = this.innerList.dom;
1508 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1509 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1510 //this.list.beginUpdate();
1511 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1512 this.list.alignTo(this.inputEl(), this.listAlign);
1513 this.list.alignTo(this.inputEl(), this.listAlign);
1514 //this.list.endUpdate();
1518 onEmptyResults : function(){
1520 if(this.tickable && this.editable){
1521 this.restrictHeight();
1529 * Returns true if the dropdown list is expanded, else false.
1531 isExpanded : function(){
1532 return this.list.isVisible();
1536 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1537 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1538 * @param {String} value The data value of the item to select
1539 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1540 * selected item if it is not currently in view (defaults to true)
1541 * @return {Boolean} True if the value matched an item in the list, else false
1543 selectByValue : function(v, scrollIntoView){
1544 if(v !== undefined && v !== null){
1545 var r = this.findRecord(this.valueField || this.displayField, v);
1547 this.select(this.store.indexOf(r), scrollIntoView);
1555 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1556 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1557 * @param {Number} index The zero-based index of the list item to select
1558 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1559 * selected item if it is not currently in view (defaults to true)
1561 select : function(index, scrollIntoView){
1562 this.selectedIndex = index;
1563 this.view.select(index);
1564 if(scrollIntoView !== false){
1565 var el = this.view.getNode(index);
1567 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1570 this.list.scrollChildIntoView(el, false);
1576 selectNext : function(){
1577 var ct = this.store.getCount();
1579 if(this.selectedIndex == -1){
1581 }else if(this.selectedIndex < ct-1){
1582 this.select(this.selectedIndex+1);
1588 selectPrev : function(){
1589 var ct = this.store.getCount();
1591 if(this.selectedIndex == -1){
1593 }else if(this.selectedIndex != 0){
1594 this.select(this.selectedIndex-1);
1600 onKeyUp : function(e){
1601 if(this.editable !== false && !e.isSpecialKey()){
1602 this.lastKey = e.getKey();
1603 this.dqTask.delay(this.queryDelay);
1608 validateBlur : function(){
1609 return !this.list || !this.list.isVisible();
1613 initQuery : function(){
1615 var v = this.getRawValue();
1617 if(this.tickable && this.editable){
1618 v = this.tickableInputEl().getValue();
1625 doForce : function(){
1626 if(this.inputEl().dom.value.length > 0){
1627 this.inputEl().dom.value =
1628 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1634 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1635 * query allowing the query action to be canceled if needed.
1636 * @param {String} query The SQL query to execute
1637 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1638 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1639 * saved in the current store (defaults to false)
1641 doQuery : function(q, forceAll){
1643 if(q === undefined || q === null){
1652 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1657 forceAll = qe.forceAll;
1658 if(forceAll === true || (q.length >= this.minChars)){
1660 this.hasQuery = true;
1662 if(this.lastQuery != q || this.alwaysQuery){
1664 if(this.mode == 'local'){
1665 this.selectedIndex = -1;
1667 this.store.clearFilter();
1670 if(this.specialFilter){
1671 this.fireEvent('specialfilter', this);
1676 this.store.filter(this.displayField, q);
1679 this.store.fireEvent("datachanged", this.store);
1686 this.store.baseParams[this.queryParam] = q;
1688 var options = {params : this.getParams(q)};
1692 options.params.start = this.page * this.pageSize;
1695 this.store.load(options);
1698 * this code will make the page width larger, at the beginning, the list not align correctly,
1699 * we should expand the list on onLoad
1705 this.selectedIndex = -1;
1710 this.loadNext = false;
1714 getParams : function(q){
1716 //p[this.queryParam] = q;
1720 p.limit = this.pageSize;
1726 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1728 collapse : function(){
1729 if(!this.isExpanded()){
1735 this.hasFocus = false;
1739 this.cancelBtn.hide();
1740 this.trigger.show();
1743 this.tickableInputEl().dom.value = '';
1744 this.tickableInputEl().blur();
1749 Roo.get(document).un('mousedown', this.collapseIf, this);
1750 Roo.get(document).un('mousewheel', this.collapseIf, this);
1751 if (!this.editable) {
1752 Roo.get(document).un('keydown', this.listKeyPress, this);
1754 this.fireEvent('collapse', this);
1760 collapseIf : function(e){
1761 var in_combo = e.within(this.el);
1762 var in_list = e.within(this.list);
1763 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1765 if (in_combo || in_list || is_list) {
1766 //e.stopPropagation();
1771 this.onTickableFooterButtonClick(e, false, false);
1779 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1781 expand : function(){
1783 if(this.isExpanded() || !this.hasFocus){
1787 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1788 this.list.setWidth(lw);
1794 this.restrictHeight();
1798 this.tickItems = Roo.apply([], this.item);
1801 this.cancelBtn.show();
1802 this.trigger.hide();
1805 this.tickableInputEl().focus();
1810 Roo.get(document).on('mousedown', this.collapseIf, this);
1811 Roo.get(document).on('mousewheel', this.collapseIf, this);
1812 if (!this.editable) {
1813 Roo.get(document).on('keydown', this.listKeyPress, this);
1816 this.fireEvent('expand', this);
1820 // Implements the default empty TriggerField.onTriggerClick function
1821 onTriggerClick : function(e)
1823 Roo.log('trigger click');
1825 if(this.disabled || !this.triggerList){
1830 this.loadNext = false;
1832 if(this.isExpanded()){
1834 if (!this.blockFocus) {
1835 this.inputEl().focus();
1839 this.hasFocus = true;
1840 if(this.triggerAction == 'all') {
1841 this.doQuery(this.allQuery, true);
1843 this.doQuery(this.getRawValue());
1845 if (!this.blockFocus) {
1846 this.inputEl().focus();
1851 onTickableTriggerClick : function(e)
1858 this.loadNext = false;
1859 this.hasFocus = true;
1861 if(this.triggerAction == 'all') {
1862 this.doQuery(this.allQuery, true);
1864 this.doQuery(this.getRawValue());
1868 onSearchFieldClick : function(e)
1870 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1871 this.onTickableFooterButtonClick(e, false, false);
1875 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1880 this.loadNext = false;
1881 this.hasFocus = true;
1883 if(this.triggerAction == 'all') {
1884 this.doQuery(this.allQuery, true);
1886 this.doQuery(this.getRawValue());
1890 listKeyPress : function(e)
1892 //Roo.log('listkeypress');
1893 // scroll to first matching element based on key pres..
1894 if (e.isSpecialKey()) {
1897 var k = String.fromCharCode(e.getKey()).toUpperCase();
1900 var csel = this.view.getSelectedNodes();
1901 var cselitem = false;
1903 var ix = this.view.indexOf(csel[0]);
1904 cselitem = this.store.getAt(ix);
1905 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1911 this.store.each(function(v) {
1913 // start at existing selection.
1914 if (cselitem.id == v.id) {
1920 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1921 match = this.store.indexOf(v);
1927 if (match === false) {
1928 return true; // no more action?
1931 this.view.select(match);
1932 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1933 sn.scrollIntoView(sn.dom.parentNode, false);
1936 onViewScroll : function(e, t){
1938 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){
1942 this.hasQuery = true;
1944 this.loading = this.list.select('.loading', true).first();
1946 if(this.loading === null){
1947 this.list.createChild({
1949 cls: 'loading roo-select2-more-results roo-select2-active',
1950 html: 'Loading more results...'
1953 this.loading = this.list.select('.loading', true).first();
1955 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1957 this.loading.hide();
1960 this.loading.show();
1965 this.loadNext = true;
1967 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1972 addItem : function(o)
1974 var dv = ''; // display value
1976 if (this.displayField) {
1977 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1979 // this is an error condition!!!
1980 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1987 var choice = this.choices.createChild({
1989 cls: 'roo-select2-search-choice',
1998 cls: 'roo-select2-search-choice-close',
2003 }, this.searchField);
2005 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2007 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2015 this.inputEl().dom.value = '';
2020 onRemoveItem : function(e, _self, o)
2024 this.lastItem = Roo.apply([], this.item);
2026 var index = this.item.indexOf(o.data) * 1;
2029 Roo.log('not this item?!');
2033 this.item.splice(index, 1);
2038 this.fireEvent('remove', this, e);
2044 syncValue : function()
2046 if(!this.item.length){
2053 Roo.each(this.item, function(i){
2054 if(_this.valueField){
2055 value.push(i[_this.valueField]);
2062 this.value = value.join(',');
2064 if(this.hiddenField){
2065 this.hiddenField.dom.value = this.value;
2068 this.store.fireEvent("datachanged", this.store);
2073 clearItem : function()
2081 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2089 if(this.tickable && !Roo.isTouch){
2090 this.view.refresh();
2094 inputEl: function ()
2096 if(Roo.isIOS && this.useNativeIOS){
2097 return this.el.select('select.roo-ios-select', true).first();
2100 if(Roo.isTouch && this.mobileTouchView){
2101 return this.el.select('input.form-control',true).first();
2105 return this.searchField;
2108 return this.el.select('input.form-control',true).first();
2111 onTickableFooterButtonClick : function(e, btn, el)
2115 this.lastItem = Roo.apply([], this.item);
2117 if(btn && btn.name == 'cancel'){
2118 this.tickItems = Roo.apply([], this.item);
2127 Roo.each(this.tickItems, function(o){
2135 validate : function()
2137 var v = this.getRawValue();
2140 v = this.getValue();
2143 if(this.disabled || this.allowBlank || v.length){
2152 tickableInputEl : function()
2154 if(!this.tickable || !this.editable){
2155 return this.inputEl();
2158 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2162 getAutoCreateTouchView : function()
2167 cls: 'form-group' //input-group
2173 type : this.inputType,
2174 cls : 'form-control x-combo-noedit',
2175 autocomplete: 'new-password',
2176 placeholder : this.placeholder || '',
2181 input.name = this.name;
2185 input.cls += ' input-' + this.size;
2188 if (this.disabled) {
2189 input.disabled = true;
2200 inputblock.cls += ' input-group';
2202 inputblock.cn.unshift({
2204 cls : 'input-group-addon',
2209 if(this.removable && !this.multiple){
2210 inputblock.cls += ' roo-removable';
2212 inputblock.cn.push({
2215 cls : 'roo-combo-removable-btn close'
2219 if(this.hasFeedback && !this.allowBlank){
2221 inputblock.cls += ' has-feedback';
2223 inputblock.cn.push({
2225 cls: 'glyphicon form-control-feedback'
2232 inputblock.cls += (this.before) ? '' : ' input-group';
2234 inputblock.cn.push({
2236 cls : 'input-group-addon',
2247 cls: 'form-hidden-field'
2261 cls: 'form-hidden-field'
2265 cls: 'roo-select2-choices',
2269 cls: 'roo-select2-search-field',
2282 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2288 if(!this.multiple && this.showToggleBtn){
2295 if (this.caret != false) {
2298 cls: 'fa fa-' + this.caret
2305 cls : 'input-group-addon btn dropdown-toggle',
2310 cls: 'combobox-clear',
2324 combobox.cls += ' roo-select2-container-multi';
2327 var align = this.labelAlign || this.parentLabelAlign();
2329 if (align ==='left' && this.fieldLabel.length) {
2334 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2335 tooltip : 'This field is required'
2339 cls : 'control-label',
2340 html : this.fieldLabel
2351 var labelCfg = cfg.cn[1];
2352 var contentCfg = cfg.cn[2];
2355 if(this.indicatorpos == 'right'){
2359 cls : 'control-label',
2360 html : this.fieldLabel
2364 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2365 tooltip : 'This field is required'
2378 labelCfg = cfg.cn[0];
2379 contentCfg = cfg.cn[2];
2381 if(this.labelWidth > 12){
2382 labelCfg.style = "width: " + this.labelWidth + 'px';
2385 if(this.labelWidth < 13 && this.labelmd == 0){
2386 this.labelmd = this.labelWidth;
2389 if(this.labellg > 0){
2390 labelCfg.cls += ' col-lg-' + this.labellg;
2391 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2394 if(this.labelmd > 0){
2395 labelCfg.cls += ' col-md-' + this.labelmd;
2396 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2399 if(this.labelsm > 0){
2400 labelCfg.cls += ' col-sm-' + this.labelsm;
2401 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2404 if(this.labelxs > 0){
2405 labelCfg.cls += ' col-xs-' + this.labelxs;
2406 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2410 } else if ( this.fieldLabel.length) {
2414 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2415 tooltip : 'This field is required'
2419 cls : 'control-label',
2420 html : this.fieldLabel
2431 if(this.indicatorpos == 'right'){
2435 cls : 'control-label',
2436 html : this.fieldLabel
2441 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2442 tooltip : 'This field is required'
2457 var settings = this;
2459 ['xs','sm','md','lg'].map(function(size){
2460 if (settings[size]) {
2461 cfg.cls += ' col-' + size + '-' + settings[size];
2468 initTouchView : function()
2470 this.renderTouchView();
2472 this.touchViewEl.on('scroll', function(){
2473 this.el.dom.scrollTop = 0;
2476 this.originalValue = this.getValue();
2478 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2480 this.inputEl().on("click", this.showTouchView, this);
2481 if (this.triggerEl) {
2482 this.triggerEl.on("click", this.showTouchView, this);
2486 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2487 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2489 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2491 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2492 this.store.on('load', this.onTouchViewLoad, this);
2493 this.store.on('loadexception', this.onTouchViewLoadException, this);
2495 if(this.hiddenName){
2497 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2499 this.hiddenField.dom.value =
2500 this.hiddenValue !== undefined ? this.hiddenValue :
2501 this.value !== undefined ? this.value : '';
2503 this.el.dom.removeAttribute('name');
2504 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2508 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2509 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2512 if(this.removable && !this.multiple){
2513 var close = this.closeTriggerEl();
2515 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2516 close.on('click', this.removeBtnClick, this, close);
2520 * fix the bug in Safari iOS8
2522 this.inputEl().on("focus", function(e){
2523 document.activeElement.blur();
2531 renderTouchView : function()
2533 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2534 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2536 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2537 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2539 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2540 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2541 this.touchViewBodyEl.setStyle('overflow', 'auto');
2543 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2544 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2546 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2547 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2551 showTouchView : function()
2557 this.touchViewHeaderEl.hide();
2559 if(this.modalTitle.length){
2560 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2561 this.touchViewHeaderEl.show();
2564 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2565 this.touchViewEl.show();
2567 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2568 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2569 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2571 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2573 if(this.modalTitle.length){
2574 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2577 this.touchViewBodyEl.setHeight(bodyHeight);
2581 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2583 this.touchViewEl.addClass('in');
2586 this.doTouchViewQuery();
2590 hideTouchView : function()
2592 this.touchViewEl.removeClass('in');
2596 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2598 this.touchViewEl.setStyle('display', 'none');
2603 setTouchViewValue : function()
2610 Roo.each(this.tickItems, function(o){
2615 this.hideTouchView();
2618 doTouchViewQuery : function()
2627 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2631 if(!this.alwaysQuery || this.mode == 'local'){
2632 this.onTouchViewLoad();
2639 onTouchViewBeforeLoad : function(combo,opts)
2645 onTouchViewLoad : function()
2647 if(this.store.getCount() < 1){
2648 this.onTouchViewEmptyResults();
2652 this.clearTouchView();
2654 var rawValue = this.getRawValue();
2656 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2658 this.tickItems = [];
2660 this.store.data.each(function(d, rowIndex){
2661 var row = this.touchViewListGroup.createChild(template);
2663 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2664 row.addClass(d.data.cls);
2667 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2670 html : d.data[this.displayField]
2673 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2674 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2677 row.removeClass('selected');
2678 if(!this.multiple && this.valueField &&
2679 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2682 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2683 row.addClass('selected');
2686 if(this.multiple && this.valueField &&
2687 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2691 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2692 this.tickItems.push(d.data);
2695 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2699 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2701 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2703 if(this.modalTitle.length){
2704 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2707 var listHeight = this.touchViewListGroup.getHeight();
2711 if(firstChecked && listHeight > bodyHeight){
2712 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2717 onTouchViewLoadException : function()
2719 this.hideTouchView();
2722 onTouchViewEmptyResults : function()
2724 this.clearTouchView();
2726 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2728 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2732 clearTouchView : function()
2734 this.touchViewListGroup.dom.innerHTML = '';
2737 onTouchViewClick : function(e, el, o)
2742 var rowIndex = o.rowIndex;
2744 var r = this.store.getAt(rowIndex);
2746 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2749 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2750 c.dom.removeAttribute('checked');
2753 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2755 this.setFromData(r.data);
2757 var close = this.closeTriggerEl();
2763 this.hideTouchView();
2765 this.fireEvent('select', this, r, rowIndex);
2770 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2771 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2772 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2776 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2777 this.addItem(r.data);
2778 this.tickItems.push(r.data);
2782 getAutoCreateNativeIOS : function()
2785 cls: 'form-group' //input-group,
2790 cls : 'roo-ios-select'
2794 combobox.name = this.name;
2797 if (this.disabled) {
2798 combobox.disabled = true;
2801 var settings = this;
2803 ['xs','sm','md','lg'].map(function(size){
2804 if (settings[size]) {
2805 cfg.cls += ' col-' + size + '-' + settings[size];
2815 initIOSView : function()
2817 this.store.on('load', this.onIOSViewLoad, this);
2822 onIOSViewLoad : function()
2824 if(this.store.getCount() < 1){
2828 this.clearIOSView();
2830 if(this.allowBlank) {
2832 var default_text = '-- SELECT --';
2834 var opt = this.inputEl().createChild({
2841 o[this.valueField] = 0;
2842 o[this.displayField] = default_text;
2844 this.ios_options.push({
2851 this.store.data.each(function(d, rowIndex){
2855 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2856 html = d.data[this.displayField];
2861 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2862 value = d.data[this.valueField];
2871 if(this.value == d.data[this.valueField]){
2872 option['selected'] = true;
2875 var opt = this.inputEl().createChild(option);
2877 this.ios_options.push({
2884 this.inputEl().on('change', function(){
2885 this.fireEvent('select', this);
2890 clearIOSView: function()
2892 this.inputEl().dom.innerHTML = '';
2894 this.ios_options = [];
2897 setIOSValue: function(v)
2901 if(!this.ios_options){
2905 Roo.each(this.ios_options, function(opts){
2907 opts.el.dom.removeAttribute('selected');
2909 if(opts.data[this.valueField] != v){
2913 opts.el.dom.setAttribute('selected', true);
2919 * @cfg {Boolean} grow
2923 * @cfg {Number} growMin
2927 * @cfg {Number} growMax
2936 Roo.apply(Roo.bootstrap.ComboBox, {
2940 cls: 'modal-header',
2962 cls: 'list-group-item',
2966 cls: 'roo-combobox-list-group-item-value'
2970 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2984 listItemCheckbox : {
2986 cls: 'list-group-item',
2990 cls: 'roo-combobox-list-group-item-value'
2994 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3010 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3015 cls: 'modal-footer',
3023 cls: 'col-xs-6 text-left',
3026 cls: 'btn btn-danger roo-touch-view-cancel',
3032 cls: 'col-xs-6 text-right',
3035 cls: 'btn btn-success roo-touch-view-ok',
3046 Roo.apply(Roo.bootstrap.ComboBox, {
3048 touchViewTemplate : {
3050 cls: 'modal fade roo-combobox-touch-view',
3054 cls: 'modal-dialog',
3055 style : 'position:fixed', // we have to fix position....
3059 cls: 'modal-content',
3061 Roo.bootstrap.ComboBox.header,
3062 Roo.bootstrap.ComboBox.body,
3063 Roo.bootstrap.ComboBox.footer