7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
19 * @cfg {String} emptyTitle default ''
21 * Create a new ComboBox.
22 * @param {Object} config Configuration options
24 Roo.bootstrap.ComboBox = function(config){
25 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
29 * Fires when the dropdown list is expanded
30 * @param {Roo.bootstrap.ComboBox} combo This combo box
35 * Fires when the dropdown list is collapsed
36 * @param {Roo.bootstrap.ComboBox} combo This combo box
41 * Fires before a list item is selected. Return false to cancel the selection.
42 * @param {Roo.bootstrap.ComboBox} combo This combo box
43 * @param {Roo.data.Record} record The data record returned from the underlying store
44 * @param {Number} index The index of the selected item in the dropdown list
46 'beforeselect' : true,
49 * Fires when a list item is selected
50 * @param {Roo.bootstrap.ComboBox} combo This combo box
51 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
52 * @param {Number} index The index of the selected item in the dropdown list
57 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
58 * The event object passed has these properties:
59 * @param {Roo.bootstrap.ComboBox} combo This combo box
60 * @param {String} query The query
61 * @param {Boolean} forceAll true to force "all" query
62 * @param {Boolean} cancel true to cancel the query
63 * @param {Object} e The query event object
68 * Fires when the 'add' icon is pressed (add a listener to enable add button)
69 * @param {Roo.bootstrap.ComboBox} combo This combo box
74 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
75 * @param {Roo.bootstrap.ComboBox} combo This combo box
76 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
81 * Fires when the remove value from the combobox array
82 * @param {Roo.bootstrap.ComboBox} combo This combo box
87 * Fires when the remove value from the combobox array
88 * @param {Roo.bootstrap.ComboBox} combo This combo box
92 * @event specialfilter
93 * Fires when specialfilter
94 * @param {Roo.bootstrap.ComboBox} combo This combo box
96 'specialfilter' : true,
99 * Fires when tick the element
100 * @param {Roo.bootstrap.ComboBox} combo This combo box
104 * @event touchviewdisplay
105 * Fires when touch view require special display (default is using displayField)
106 * @param {Roo.bootstrap.ComboBox} combo This combo box
107 * @param {Object} cfg set html .
109 'touchviewdisplay' : true
116 this.selectedIndex = -1;
117 if(this.mode == 'local'){
118 if(config.queryDelay === undefined){
119 this.queryDelay = 10;
121 if(config.minChars === undefined){
127 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
130 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
131 * rendering into an Roo.Editor, defaults to false)
134 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
135 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
138 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
141 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
142 * the dropdown list (defaults to undefined, with no header element)
146 * @cfg {String/Roo.Template} tpl The template to use to render the output
150 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
152 listWidth: undefined,
154 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
155 * mode = 'remote' or 'text' if mode = 'local')
157 displayField: undefined,
160 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
161 * mode = 'remote' or 'value' if mode = 'local').
162 * Note: use of a valueField requires the user make a selection
163 * in order for a value to be mapped.
165 valueField: undefined,
167 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
172 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
173 * field's data value (defaults to the underlying DOM element's name)
175 hiddenName: undefined,
177 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
181 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
183 selectedClass: 'active',
186 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
190 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
191 * anchor positions (defaults to 'tl-bl')
195 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
199 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
200 * query specified by the allQuery config option (defaults to 'query')
202 triggerAction: 'query',
204 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
205 * (defaults to 4, does not apply if editable = false)
209 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
210 * delay (typeAheadDelay) if it matches a known value (defaults to false)
214 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
215 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
219 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
220 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
224 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
225 * when editable = true (defaults to false)
229 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
233 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
234 * when mode = 'remote' (defaults to 'Loading...')
236 loadingText: 'Loading...',
238 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
242 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
246 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
247 * traditional select (defaults to true)
251 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
255 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
259 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
260 * listWidth has a higher value)
264 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
265 * allow the user to set arbitrary text into the field (defaults to false)
267 forceSelection:false,
269 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
270 * if typeAhead = true (defaults to 250)
272 typeAheadDelay : 250,
274 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
275 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
277 valueNotFoundText : undefined,
279 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
284 * @cfg {Boolean} disableClear Disable showing of clear button.
286 disableClear : false,
288 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
293 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
298 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
300 invalidClass : "has-warning",
303 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
305 validClass : "has-success",
308 * @cfg {Boolean} specialFilter (true|false) special filter default false
310 specialFilter : false,
313 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
315 mobileTouchView : true,
318 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
320 useNativeIOS : false,
334 btnPosition : 'right',
336 showToggleBtn : true,
338 emptyResultText: 'Empty',
339 triggerText : 'Select',
342 // element that contains real text value.. (when hidden is used..)
344 getAutoCreate : function()
349 * Render classic select for iso
352 if(Roo.isIOS && this.useNativeIOS){
353 cfg = this.getAutoCreateNativeIOS();
361 if(Roo.isTouch && this.mobileTouchView){
362 cfg = this.getAutoCreateTouchView();
370 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
371 if(this.name == 'info_year_invest_id_display_name'){
372 Roo.log('cfg.................................................');
379 * ComboBox with tickable selections
382 var align = this.labelAlign || this.parentLabelAlign();
385 cls : 'form-group roo-combobox-tickable' //input-group
388 var btn_text_select = '';
389 var btn_text_done = '';
390 var btn_text_cancel = '';
392 if (this.btn_text_show) {
393 btn_text_select = 'Select';
394 btn_text_done = 'Done';
395 btn_text_cancel = 'Cancel';
400 cls : 'tickable-buttons',
405 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
406 //html : this.triggerText
407 html: btn_text_select
413 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
421 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
423 html: btn_text_cancel
431 cls: 'roo-select2-search-field-input'
437 Roo.each(buttons.cn, function(c){
439 c.cls += ' btn-' + _this.size;
442 if (_this.disabled) {
453 cls: 'form-hidden-field'
457 cls: 'roo-select2-choices',
461 cls: 'roo-select2-search-field',
472 cls: 'roo-select2-container input-group roo-select2-container-multi',
477 // cls: 'typeahead typeahead-long dropdown-menu',
478 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
483 if(this.hasFeedback && !this.allowBlank){
487 cls: 'glyphicon form-control-feedback'
490 combobox.cn.push(feedback);
494 if (align ==='left' && this.fieldLabel.length) {
496 cfg.cls += ' roo-form-group-label-left';
501 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
502 tooltip : 'This field is required'
507 cls : 'control-label',
508 html : this.fieldLabel
520 var labelCfg = cfg.cn[1];
521 var contentCfg = cfg.cn[2];
524 if(this.indicatorpos == 'right'){
530 cls : 'control-label',
534 html : this.fieldLabel
538 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
539 tooltip : 'This field is required'
554 labelCfg = cfg.cn[0];
555 contentCfg = cfg.cn[1];
559 if(this.labelWidth > 12){
560 labelCfg.style = "width: " + this.labelWidth + 'px';
563 if(this.labelWidth < 13 && this.labelmd == 0){
564 this.labelmd = this.labelWidth;
567 if(this.labellg > 0){
568 labelCfg.cls += ' col-lg-' + this.labellg;
569 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
572 if(this.labelmd > 0){
573 labelCfg.cls += ' col-md-' + this.labelmd;
574 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
577 if(this.labelsm > 0){
578 labelCfg.cls += ' col-sm-' + this.labelsm;
579 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
582 if(this.labelxs > 0){
583 labelCfg.cls += ' col-xs-' + this.labelxs;
584 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
588 } else if ( this.fieldLabel.length) {
589 // Roo.log(" label");
593 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
594 tooltip : 'This field is required'
598 //cls : 'input-group-addon',
599 html : this.fieldLabel
607 if(this.indicatorpos == 'right'){
612 //cls : 'input-group-addon',
616 html : this.fieldLabel
620 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
621 tooltip : 'This field is required'
636 // Roo.log(" no label && no align");
643 ['xs','sm','md','lg'].map(function(size){
644 if (settings[size]) {
645 cfg.cls += ' col-' + size + '-' + settings[size];
653 _initEventsCalled : false,
656 initEvents: function()
658 if (this._initEventsCalled) { // as we call render... prevent looping...
661 this._initEventsCalled = true;
664 throw "can not find store for combo";
667 this.store = Roo.factory(this.store, Roo.data);
668 this.store.parent = this;
670 // if we are building from html. then this element is so complex, that we can not really
671 // use the rendered HTML.
672 // so we have to trash and replace the previous code.
673 if (Roo.XComponent.build_from_html) {
675 // remove this element....
676 var e = this.el.dom, k=0;
677 while (e ) { e = e.previousSibling; ++k;}
682 this.rendered = false;
684 this.render(this.parent().getChildContainer(true), k);
690 if(Roo.isIOS && this.useNativeIOS){
699 if(Roo.isTouch && this.mobileTouchView){
700 this.initTouchView();
705 this.initTickableEvents();
709 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
713 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
715 this.hiddenField.dom.value =
716 this.hiddenValue !== undefined ? this.hiddenValue :
717 this.value !== undefined ? this.value : '';
719 // prevent input submission
720 this.el.dom.removeAttribute('name');
721 this.hiddenField.dom.setAttribute('name', this.hiddenName);
726 // this.el.dom.setAttribute('autocomplete', 'off');
729 var cls = 'x-combo-list';
731 //this.list = new Roo.Layer({
732 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
738 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
739 _this.list.setWidth(lw);
742 this.list.on('mouseover', this.onViewOver, this);
743 this.list.on('mousemove', this.onViewMove, this);
745 this.list.on('scroll', this.onViewScroll, this);
748 this.list.swallowEvent('mousewheel');
749 this.assetHeight = 0;
752 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
753 this.assetHeight += this.header.getHeight();
756 this.innerList = this.list.createChild({cls:cls+'-inner'});
757 this.innerList.on('mouseover', this.onViewOver, this);
758 this.innerList.on('mousemove', this.onViewMove, this);
759 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
761 if(this.allowBlank && !this.pageSize && !this.disableClear){
762 this.footer = this.list.createChild({cls:cls+'-ft'});
763 this.pageTb = new Roo.Toolbar(this.footer);
767 this.footer = this.list.createChild({cls:cls+'-ft'});
768 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
769 {pageSize: this.pageSize});
773 if (this.pageTb && this.allowBlank && !this.disableClear) {
775 this.pageTb.add(new Roo.Toolbar.Fill(), {
776 cls: 'x-btn-icon x-btn-clear',
782 _this.onSelect(false, -1);
787 this.assetHeight += this.footer.getHeight();
792 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
795 this.view = new Roo.View(this.list, this.tpl, {
796 singleSelect:true, store: this.store, selectedClass: this.selectedClass
798 //this.view.wrapEl.setDisplayed(false);
799 this.view.on('click', this.onViewClick, this);
802 this.store.on('beforeload', this.onBeforeLoad, this);
803 this.store.on('load', this.onLoad, this);
804 this.store.on('loadexception', this.onLoadException, this);
807 this.resizer = new Roo.Resizable(this.list, {
808 pinned:true, handles:'se'
810 this.resizer.on('resize', function(r, w, h){
811 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
813 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
814 this.restrictHeight();
816 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
820 this.editable = true;
821 this.setEditable(false);
826 if (typeof(this.events.add.listeners) != 'undefined') {
828 this.addicon = this.wrap.createChild(
829 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
831 this.addicon.on('click', function(e) {
832 this.fireEvent('add', this);
835 if (typeof(this.events.edit.listeners) != 'undefined') {
837 this.editicon = this.wrap.createChild(
838 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
840 this.editicon.setStyle('margin-left', '40px');
842 this.editicon.on('click', function(e) {
844 // we fire even if inothing is selected..
845 this.fireEvent('edit', this, this.lastData );
851 this.keyNav = new Roo.KeyNav(this.inputEl(), {
853 this.inKeyMode = true;
857 "down" : function(e){
858 if(!this.isExpanded()){
859 this.onTriggerClick();
861 this.inKeyMode = true;
866 "enter" : function(e){
867 // this.onViewClick();
871 if(this.fireEvent("specialkey", this, e)){
872 this.onViewClick(false);
885 if(this.fireEvent("specialkey", this, e)){
886 this.onViewClick(false);
894 doRelay : function(foo, bar, hname){
895 if(hname == 'down' || this.scope.isExpanded()){
896 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
905 this.queryDelay = Math.max(this.queryDelay || 10,
906 this.mode == 'local' ? 10 : 250);
909 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
912 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
914 if(this.editable !== false){
915 this.inputEl().on("keyup", this.onKeyUp, this);
917 if(this.forceSelection){
918 this.inputEl().on('blur', this.doForce, this);
922 this.choices = this.el.select('ul.roo-select2-choices', true).first();
923 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
927 initTickableEvents: function()
933 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
935 this.hiddenField.dom.value =
936 this.hiddenValue !== undefined ? this.hiddenValue :
937 this.value !== undefined ? this.value : '';
939 // prevent input submission
940 this.el.dom.removeAttribute('name');
941 this.hiddenField.dom.setAttribute('name', this.hiddenName);
946 // this.list = this.el.select('ul.dropdown-menu',true).first();
948 this.choices = this.el.select('ul.roo-select2-choices', true).first();
949 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
950 if(this.triggerList){
951 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
954 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
955 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
957 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
958 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
960 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
961 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
963 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
964 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
965 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
968 this.cancelBtn.hide();
973 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
974 _this.list.setWidth(lw);
977 this.list.on('mouseover', this.onViewOver, this);
978 this.list.on('mousemove', this.onViewMove, this);
980 this.list.on('scroll', this.onViewScroll, this);
983 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>';
986 this.view = new Roo.View(this.list, this.tpl, {
987 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
990 //this.view.wrapEl.setDisplayed(false);
991 this.view.on('click', this.onViewClick, this);
995 this.store.on('beforeload', this.onBeforeLoad, this);
996 this.store.on('load', this.onLoad, this);
997 this.store.on('loadexception', this.onLoadException, this);
1000 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
1002 this.inKeyMode = true;
1006 "down" : function(e){
1007 this.inKeyMode = true;
1011 "enter" : function(e){
1012 if(this.fireEvent("specialkey", this, e)){
1013 this.onViewClick(false);
1019 "esc" : function(e){
1020 this.onTickableFooterButtonClick(e, false, false);
1023 "tab" : function(e){
1024 this.fireEvent("specialkey", this, e);
1026 this.onTickableFooterButtonClick(e, false, false);
1033 doRelay : function(e, fn, key){
1034 if(this.scope.isExpanded()){
1035 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1044 this.queryDelay = Math.max(this.queryDelay || 10,
1045 this.mode == 'local' ? 10 : 250);
1048 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1051 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1054 if(this.editable !== false){
1055 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1058 this.indicator = this.indicatorEl();
1061 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1062 this.indicator.hide();
1067 onDestroy : function(){
1069 this.view.setStore(null);
1070 this.view.el.removeAllListeners();
1071 this.view.el.remove();
1072 this.view.purgeListeners();
1075 this.list.dom.innerHTML = '';
1079 this.store.un('beforeload', this.onBeforeLoad, this);
1080 this.store.un('load', this.onLoad, this);
1081 this.store.un('loadexception', this.onLoadException, this);
1083 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1087 fireKey : function(e){
1088 if(e.isNavKeyPress() && !this.list.isVisible()){
1089 this.fireEvent("specialkey", this, e);
1094 onResize: function(w, h){
1095 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1097 // if(typeof w != 'number'){
1098 // // we do not handle it!?!?
1101 // var tw = this.trigger.getWidth();
1102 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1103 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1105 // this.inputEl().setWidth( this.adjustWidth('input', x));
1107 // //this.trigger.setStyle('left', x+'px');
1109 // if(this.list && this.listWidth === undefined){
1110 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1111 // this.list.setWidth(lw);
1112 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1120 * Allow or prevent the user from directly editing the field text. If false is passed,
1121 * the user will only be able to select from the items defined in the dropdown list. This method
1122 * is the runtime equivalent of setting the 'editable' config option at config time.
1123 * @param {Boolean} value True to allow the user to directly edit the field text
1125 setEditable : function(value){
1126 if(value == this.editable){
1129 this.editable = value;
1131 this.inputEl().dom.setAttribute('readOnly', true);
1132 this.inputEl().on('mousedown', this.onTriggerClick, this);
1133 this.inputEl().addClass('x-combo-noedit');
1135 this.inputEl().dom.setAttribute('readOnly', false);
1136 this.inputEl().un('mousedown', this.onTriggerClick, this);
1137 this.inputEl().removeClass('x-combo-noedit');
1143 onBeforeLoad : function(combo,opts){
1148 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1150 this.restrictHeight();
1151 this.selectedIndex = -1;
1155 onLoad : function(){
1157 this.hasQuery = false;
1163 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1164 this.loading.hide();
1167 if(this.store.getCount() > 0){
1170 this.restrictHeight();
1171 if(this.lastQuery == this.allQuery){
1172 if(this.editable && !this.tickable){
1173 this.inputEl().dom.select();
1177 !this.selectByValue(this.value, true) &&
1180 !this.store.lastOptions ||
1181 typeof(this.store.lastOptions.add) == 'undefined' ||
1182 this.store.lastOptions.add != true
1185 this.select(0, true);
1191 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1192 this.taTask.delay(this.typeAheadDelay);
1196 this.onEmptyResults();
1202 onLoadException : function()
1204 this.hasQuery = false;
1206 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1207 this.loading.hide();
1210 if(this.tickable && this.editable){
1215 // only causes errors at present
1216 //Roo.log(this.store.reader.jsonData);
1217 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1219 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1225 onTypeAhead : function(){
1226 if(this.store.getCount() > 0){
1227 var r = this.store.getAt(0);
1228 var newValue = r.data[this.displayField];
1229 var len = newValue.length;
1230 var selStart = this.getRawValue().length;
1232 if(selStart != len){
1233 this.setRawValue(newValue);
1234 this.selectText(selStart, newValue.length);
1240 onSelect : function(record, index){
1242 if(this.fireEvent('beforeselect', this, record, index) !== false){
1244 this.setFromData(index > -1 ? record.data : false);
1247 this.fireEvent('select', this, record, index);
1252 * Returns the currently selected field value or empty string if no value is set.
1253 * @return {String} value The selected value
1255 getValue : function()
1257 if(Roo.isIOS && this.useNativeIOS){
1258 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1262 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1265 if(this.valueField){
1266 return typeof this.value != 'undefined' ? this.value : '';
1268 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1272 getRawValue : function()
1274 if(Roo.isIOS && this.useNativeIOS){
1275 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1278 var v = this.inputEl().getValue();
1284 * Clears any text/value currently set in the field
1286 clearValue : function(){
1288 if(this.hiddenField){
1289 this.hiddenField.dom.value = '';
1292 this.setRawValue('');
1293 this.lastSelectionText = '';
1294 this.lastData = false;
1296 var close = this.closeTriggerEl();
1307 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1308 * will be displayed in the field. If the value does not match the data value of an existing item,
1309 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1310 * Otherwise the field will be blank (although the value will still be set).
1311 * @param {String} value The value to match
1313 setValue : function(v)
1315 if(Roo.isIOS && this.useNativeIOS){
1316 this.setIOSValue(v);
1326 if(this.valueField){
1327 var r = this.findRecord(this.valueField, v);
1329 text = r.data[this.displayField];
1330 }else if(this.valueNotFoundText !== undefined){
1331 text = this.valueNotFoundText;
1334 this.lastSelectionText = text;
1335 if(this.hiddenField){
1336 this.hiddenField.dom.value = v;
1338 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1341 var close = this.closeTriggerEl();
1344 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1350 * @property {Object} the last set data for the element
1355 * Sets the value of the field based on a object which is related to the record format for the store.
1356 * @param {Object} value the value to set as. or false on reset?
1358 setFromData : function(o){
1365 var dv = ''; // display value
1366 var vv = ''; // value value..
1368 if (this.displayField) {
1369 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1371 // this is an error condition!!!
1372 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1375 if(this.valueField){
1376 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1379 var close = this.closeTriggerEl();
1382 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1385 if(this.hiddenField){
1386 this.hiddenField.dom.value = vv;
1388 this.lastSelectionText = dv;
1389 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1393 // no hidden field.. - we store the value in 'value', but still display
1394 // display field!!!!
1395 this.lastSelectionText = dv;
1396 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1404 // overridden so that last data is reset..
1411 this.setValue(this.originalValue);
1412 //this.clearInvalid();
1413 this.lastData = false;
1415 this.view.clearSelections();
1421 findRecord : function(prop, value){
1423 if(this.store.getCount() > 0){
1424 this.store.each(function(r){
1425 if(r.data[prop] == value){
1437 // returns hidden if it's set..
1438 if (!this.rendered) {return ''};
1439 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1443 onViewMove : function(e, t){
1444 this.inKeyMode = false;
1448 onViewOver : function(e, t){
1449 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1452 var item = this.view.findItemFromChild(t);
1455 var index = this.view.indexOf(item);
1456 this.select(index, false);
1461 onViewClick : function(view, doFocus, el, e)
1463 var index = this.view.getSelectedIndexes()[0];
1465 var r = this.store.getAt(index);
1469 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1476 Roo.each(this.tickItems, function(v,k){
1478 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1480 _this.tickItems.splice(k, 1);
1482 if(typeof(e) == 'undefined' && view == false){
1483 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1495 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1496 this.tickItems.push(r.data);
1499 if(typeof(e) == 'undefined' && view == false){
1500 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1507 this.onSelect(r, index);
1509 if(doFocus !== false && !this.blockFocus){
1510 this.inputEl().focus();
1515 restrictHeight : function(){
1516 //this.innerList.dom.style.height = '';
1517 //var inner = this.innerList.dom;
1518 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1519 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1520 //this.list.beginUpdate();
1521 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1522 this.list.alignTo(this.inputEl(), this.listAlign);
1523 this.list.alignTo(this.inputEl(), this.listAlign);
1524 //this.list.endUpdate();
1528 onEmptyResults : function(){
1530 if(this.tickable && this.editable){
1531 this.restrictHeight();
1539 * Returns true if the dropdown list is expanded, else false.
1541 isExpanded : function(){
1542 return this.list.isVisible();
1546 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1547 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1548 * @param {String} value The data value of the item to select
1549 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1550 * selected item if it is not currently in view (defaults to true)
1551 * @return {Boolean} True if the value matched an item in the list, else false
1553 selectByValue : function(v, scrollIntoView){
1554 if(v !== undefined && v !== null){
1555 var r = this.findRecord(this.valueField || this.displayField, v);
1557 this.select(this.store.indexOf(r), scrollIntoView);
1565 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1566 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1567 * @param {Number} index The zero-based index of the list item to select
1568 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1569 * selected item if it is not currently in view (defaults to true)
1571 select : function(index, scrollIntoView){
1572 this.selectedIndex = index;
1573 this.view.select(index);
1574 if(scrollIntoView !== false){
1575 var el = this.view.getNode(index);
1577 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1580 this.list.scrollChildIntoView(el, false);
1586 selectNext : function(){
1587 var ct = this.store.getCount();
1589 if(this.selectedIndex == -1){
1591 }else if(this.selectedIndex < ct-1){
1592 this.select(this.selectedIndex+1);
1598 selectPrev : function(){
1599 var ct = this.store.getCount();
1601 if(this.selectedIndex == -1){
1603 }else if(this.selectedIndex != 0){
1604 this.select(this.selectedIndex-1);
1610 onKeyUp : function(e){
1611 if(this.editable !== false && !e.isSpecialKey()){
1612 this.lastKey = e.getKey();
1613 this.dqTask.delay(this.queryDelay);
1618 validateBlur : function(){
1619 return !this.list || !this.list.isVisible();
1623 initQuery : function(){
1625 var v = this.getRawValue();
1627 if(this.tickable && this.editable){
1628 v = this.tickableInputEl().getValue();
1635 doForce : function(){
1636 if(this.inputEl().dom.value.length > 0){
1637 this.inputEl().dom.value =
1638 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1644 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1645 * query allowing the query action to be canceled if needed.
1646 * @param {String} query The SQL query to execute
1647 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1648 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1649 * saved in the current store (defaults to false)
1651 doQuery : function(q, forceAll){
1653 if(q === undefined || q === null){
1662 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1667 forceAll = qe.forceAll;
1668 if(forceAll === true || (q.length >= this.minChars)){
1670 this.hasQuery = true;
1672 if(this.lastQuery != q || this.alwaysQuery){
1674 if(this.mode == 'local'){
1675 this.selectedIndex = -1;
1677 this.store.clearFilter();
1680 if(this.specialFilter){
1681 this.fireEvent('specialfilter', this);
1686 this.store.filter(this.displayField, q);
1689 this.store.fireEvent("datachanged", this.store);
1696 this.store.baseParams[this.queryParam] = q;
1698 var options = {params : this.getParams(q)};
1702 options.params.start = this.page * this.pageSize;
1705 this.store.load(options);
1708 * this code will make the page width larger, at the beginning, the list not align correctly,
1709 * we should expand the list on onLoad
1715 this.selectedIndex = -1;
1720 this.loadNext = false;
1724 getParams : function(q){
1726 //p[this.queryParam] = q;
1730 p.limit = this.pageSize;
1736 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1738 collapse : function(){
1739 if(!this.isExpanded()){
1745 this.hasFocus = false;
1749 this.cancelBtn.hide();
1750 this.trigger.show();
1753 this.tickableInputEl().dom.value = '';
1754 this.tickableInputEl().blur();
1759 Roo.get(document).un('mousedown', this.collapseIf, this);
1760 Roo.get(document).un('mousewheel', this.collapseIf, this);
1761 if (!this.editable) {
1762 Roo.get(document).un('keydown', this.listKeyPress, this);
1764 this.fireEvent('collapse', this);
1770 collapseIf : function(e){
1771 var in_combo = e.within(this.el);
1772 var in_list = e.within(this.list);
1773 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1775 if (in_combo || in_list || is_list) {
1776 //e.stopPropagation();
1781 this.onTickableFooterButtonClick(e, false, false);
1789 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1791 expand : function(){
1793 if(this.isExpanded() || !this.hasFocus){
1797 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1798 this.list.setWidth(lw);
1804 this.restrictHeight();
1808 this.tickItems = Roo.apply([], this.item);
1811 this.cancelBtn.show();
1812 this.trigger.hide();
1815 this.tickableInputEl().focus();
1820 Roo.get(document).on('mousedown', this.collapseIf, this);
1821 Roo.get(document).on('mousewheel', this.collapseIf, this);
1822 if (!this.editable) {
1823 Roo.get(document).on('keydown', this.listKeyPress, this);
1826 this.fireEvent('expand', this);
1830 // Implements the default empty TriggerField.onTriggerClick function
1831 onTriggerClick : function(e)
1833 Roo.log('trigger click');
1835 if(this.disabled || !this.triggerList){
1840 this.loadNext = false;
1842 if(this.isExpanded()){
1844 if (!this.blockFocus) {
1845 this.inputEl().focus();
1849 this.hasFocus = true;
1850 if(this.triggerAction == 'all') {
1851 this.doQuery(this.allQuery, true);
1853 this.doQuery(this.getRawValue());
1855 if (!this.blockFocus) {
1856 this.inputEl().focus();
1861 onTickableTriggerClick : function(e)
1868 this.loadNext = false;
1869 this.hasFocus = true;
1871 if(this.triggerAction == 'all') {
1872 this.doQuery(this.allQuery, true);
1874 this.doQuery(this.getRawValue());
1878 onSearchFieldClick : function(e)
1880 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1881 this.onTickableFooterButtonClick(e, false, false);
1885 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1890 this.loadNext = false;
1891 this.hasFocus = true;
1893 if(this.triggerAction == 'all') {
1894 this.doQuery(this.allQuery, true);
1896 this.doQuery(this.getRawValue());
1900 listKeyPress : function(e)
1902 //Roo.log('listkeypress');
1903 // scroll to first matching element based on key pres..
1904 if (e.isSpecialKey()) {
1907 var k = String.fromCharCode(e.getKey()).toUpperCase();
1910 var csel = this.view.getSelectedNodes();
1911 var cselitem = false;
1913 var ix = this.view.indexOf(csel[0]);
1914 cselitem = this.store.getAt(ix);
1915 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1921 this.store.each(function(v) {
1923 // start at existing selection.
1924 if (cselitem.id == v.id) {
1930 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1931 match = this.store.indexOf(v);
1937 if (match === false) {
1938 return true; // no more action?
1941 this.view.select(match);
1942 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1943 sn.scrollIntoView(sn.dom.parentNode, false);
1946 onViewScroll : function(e, t){
1948 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){
1952 this.hasQuery = true;
1954 this.loading = this.list.select('.loading', true).first();
1956 if(this.loading === null){
1957 this.list.createChild({
1959 cls: 'loading roo-select2-more-results roo-select2-active',
1960 html: 'Loading more results...'
1963 this.loading = this.list.select('.loading', true).first();
1965 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1967 this.loading.hide();
1970 this.loading.show();
1975 this.loadNext = true;
1977 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1982 addItem : function(o)
1984 var dv = ''; // display value
1986 if (this.displayField) {
1987 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1989 // this is an error condition!!!
1990 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1997 var choice = this.choices.createChild({
1999 cls: 'roo-select2-search-choice',
2008 cls: 'roo-select2-search-choice-close fa fa-times',
2013 }, this.searchField);
2015 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2017 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2025 this.inputEl().dom.value = '';
2030 onRemoveItem : function(e, _self, o)
2034 this.lastItem = Roo.apply([], this.item);
2036 var index = this.item.indexOf(o.data) * 1;
2039 Roo.log('not this item?!');
2043 this.item.splice(index, 1);
2048 this.fireEvent('remove', this, e);
2054 syncValue : function()
2056 if(!this.item.length){
2063 Roo.each(this.item, function(i){
2064 if(_this.valueField){
2065 value.push(i[_this.valueField]);
2072 this.value = value.join(',');
2074 if(this.hiddenField){
2075 this.hiddenField.dom.value = this.value;
2078 this.store.fireEvent("datachanged", this.store);
2083 clearItem : function()
2091 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2099 if(this.tickable && !Roo.isTouch){
2100 this.view.refresh();
2104 inputEl: function ()
2106 if(Roo.isIOS && this.useNativeIOS){
2107 return this.el.select('select.roo-ios-select', true).first();
2110 if(Roo.isTouch && this.mobileTouchView){
2111 return this.el.select('input.form-control',true).first();
2115 return this.searchField;
2118 return this.el.select('input.form-control',true).first();
2121 onTickableFooterButtonClick : function(e, btn, el)
2125 this.lastItem = Roo.apply([], this.item);
2127 if(btn && btn.name == 'cancel'){
2128 this.tickItems = Roo.apply([], this.item);
2137 Roo.each(this.tickItems, function(o){
2145 validate : function()
2147 var v = this.getRawValue();
2150 v = this.getValue();
2153 if(this.disabled || this.allowBlank || v.length){
2162 tickableInputEl : function()
2164 if(!this.tickable || !this.editable){
2165 return this.inputEl();
2168 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2172 getAutoCreateTouchView : function()
2177 cls: 'form-group' //input-group
2183 type : this.inputType,
2184 cls : 'form-control x-combo-noedit',
2185 autocomplete: 'new-password',
2186 placeholder : this.placeholder || '',
2191 input.name = this.name;
2195 input.cls += ' input-' + this.size;
2198 if (this.disabled) {
2199 input.disabled = true;
2210 inputblock.cls += ' input-group';
2212 inputblock.cn.unshift({
2214 cls : 'input-group-addon',
2219 if(this.removable && !this.multiple){
2220 inputblock.cls += ' roo-removable';
2222 inputblock.cn.push({
2225 cls : 'roo-combo-removable-btn close'
2229 if(this.hasFeedback && !this.allowBlank){
2231 inputblock.cls += ' has-feedback';
2233 inputblock.cn.push({
2235 cls: 'glyphicon form-control-feedback'
2242 inputblock.cls += (this.before) ? '' : ' input-group';
2244 inputblock.cn.push({
2246 cls : 'input-group-addon',
2257 cls: 'form-hidden-field'
2271 cls: 'form-hidden-field'
2275 cls: 'roo-select2-choices',
2279 cls: 'roo-select2-search-field',
2292 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2298 if(!this.multiple && this.showToggleBtn){
2305 if (this.caret != false) {
2308 cls: 'fa fa-' + this.caret
2315 cls : 'input-group-addon btn dropdown-toggle',
2320 cls: 'combobox-clear',
2334 combobox.cls += ' roo-select2-container-multi';
2337 var align = this.labelAlign || this.parentLabelAlign();
2339 if (align ==='left' && this.fieldLabel.length) {
2344 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2345 tooltip : 'This field is required'
2349 cls : 'control-label',
2350 html : this.fieldLabel
2361 var labelCfg = cfg.cn[1];
2362 var contentCfg = cfg.cn[2];
2365 if(this.indicatorpos == 'right'){
2369 cls : 'control-label',
2370 html : this.fieldLabel,
2374 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2375 tooltip : 'This field is required'
2388 labelCfg = cfg.cn[0];
2389 contentCfg = cfg.cn[2];
2391 if(this.labelWidth > 12){
2392 labelCfg.style = "width: " + this.labelWidth + 'px';
2395 if(this.labelWidth < 13 && this.labelmd == 0){
2396 this.labelmd = this.labelWidth;
2399 if(this.labellg > 0){
2400 labelCfg.cls += ' col-lg-' + this.labellg;
2401 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2404 if(this.labelmd > 0){
2405 labelCfg.cls += ' col-md-' + this.labelmd;
2406 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2409 if(this.labelsm > 0){
2410 labelCfg.cls += ' col-sm-' + this.labelsm;
2411 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2414 if(this.labelxs > 0){
2415 labelCfg.cls += ' col-xs-' + this.labelxs;
2416 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2420 } else if ( this.fieldLabel.length) {
2424 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2425 tooltip : 'This field is required'
2429 cls : 'control-label',
2430 html : this.fieldLabel
2441 if(this.indicatorpos == 'right'){
2445 cls : 'control-label',
2446 html : this.fieldLabel,
2450 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2451 tooltip : 'This field is required'
2468 var settings = this;
2470 ['xs','sm','md','lg'].map(function(size){
2471 if (settings[size]) {
2472 cfg.cls += ' col-' + size + '-' + settings[size];
2479 initTouchView : function()
2481 this.renderTouchView();
2483 this.touchViewEl.on('scroll', function(){
2484 this.el.dom.scrollTop = 0;
2487 this.originalValue = this.getValue();
2489 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2491 this.inputEl().on("click", this.showTouchView, this);
2492 if (this.triggerEl) {
2493 this.triggerEl.on("click", this.showTouchView, this);
2497 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2498 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2500 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2502 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2503 this.store.on('load', this.onTouchViewLoad, this);
2504 this.store.on('loadexception', this.onTouchViewLoadException, this);
2506 if(this.hiddenName){
2508 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2510 this.hiddenField.dom.value =
2511 this.hiddenValue !== undefined ? this.hiddenValue :
2512 this.value !== undefined ? this.value : '';
2514 this.el.dom.removeAttribute('name');
2515 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2519 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2520 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2523 if(this.removable && !this.multiple){
2524 var close = this.closeTriggerEl();
2526 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2527 close.on('click', this.removeBtnClick, this, close);
2531 * fix the bug in Safari iOS8
2533 this.inputEl().on("focus", function(e){
2534 document.activeElement.blur();
2542 renderTouchView : function()
2544 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2545 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2547 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2548 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2550 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2551 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2552 this.touchViewBodyEl.setStyle('overflow', 'auto');
2554 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2555 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2557 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2558 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2562 showTouchView : function()
2568 this.touchViewHeaderEl.hide();
2570 if(this.modalTitle.length){
2571 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2572 this.touchViewHeaderEl.show();
2575 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2576 this.touchViewEl.show();
2578 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2579 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2580 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2582 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2584 if(this.modalTitle.length){
2585 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2588 this.touchViewBodyEl.setHeight(bodyHeight);
2592 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2594 this.touchViewEl.addClass('in');
2597 this.doTouchViewQuery();
2601 hideTouchView : function()
2603 this.touchViewEl.removeClass('in');
2607 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2609 this.touchViewEl.setStyle('display', 'none');
2614 setTouchViewValue : function()
2621 Roo.each(this.tickItems, function(o){
2626 this.hideTouchView();
2629 doTouchViewQuery : function()
2638 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2642 if(!this.alwaysQuery || this.mode == 'local'){
2643 this.onTouchViewLoad();
2650 onTouchViewBeforeLoad : function(combo,opts)
2656 onTouchViewLoad : function()
2658 if(this.store.getCount() < 1){
2659 this.onTouchViewEmptyResults();
2663 this.clearTouchView();
2665 var rawValue = this.getRawValue();
2667 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2669 this.tickItems = [];
2671 this.store.data.each(function(d, rowIndex){
2672 var row = this.touchViewListGroup.createChild(template);
2674 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2675 row.addClass(d.data.cls);
2678 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2681 html : d.data[this.displayField]
2684 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2685 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2688 row.removeClass('selected');
2689 if(!this.multiple && this.valueField &&
2690 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2693 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2694 row.addClass('selected');
2697 if(this.multiple && this.valueField &&
2698 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2702 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2703 this.tickItems.push(d.data);
2706 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2710 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2712 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2714 if(this.modalTitle.length){
2715 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2718 var listHeight = this.touchViewListGroup.getHeight();
2722 if(firstChecked && listHeight > bodyHeight){
2723 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2728 onTouchViewLoadException : function()
2730 this.hideTouchView();
2733 onTouchViewEmptyResults : function()
2735 this.clearTouchView();
2737 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2739 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2743 clearTouchView : function()
2745 this.touchViewListGroup.dom.innerHTML = '';
2748 onTouchViewClick : function(e, el, o)
2753 var rowIndex = o.rowIndex;
2755 var r = this.store.getAt(rowIndex);
2757 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2760 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2761 c.dom.removeAttribute('checked');
2764 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2766 this.setFromData(r.data);
2768 var close = this.closeTriggerEl();
2774 this.hideTouchView();
2776 this.fireEvent('select', this, r, rowIndex);
2781 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2782 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2783 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2787 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2788 this.addItem(r.data);
2789 this.tickItems.push(r.data);
2793 getAutoCreateNativeIOS : function()
2796 cls: 'form-group' //input-group,
2801 cls : 'roo-ios-select'
2805 combobox.name = this.name;
2808 if (this.disabled) {
2809 combobox.disabled = true;
2812 var settings = this;
2814 ['xs','sm','md','lg'].map(function(size){
2815 if (settings[size]) {
2816 cfg.cls += ' col-' + size + '-' + settings[size];
2826 initIOSView : function()
2828 this.store.on('load', this.onIOSViewLoad, this);
2833 onIOSViewLoad : function()
2835 if(this.store.getCount() < 1){
2839 this.clearIOSView();
2841 if(this.allowBlank) {
2843 var default_text = '-- SELECT --';
2845 var opt = this.inputEl().createChild({
2852 o[this.valueField] = 0;
2853 o[this.displayField] = default_text;
2855 this.ios_options.push({
2862 this.store.data.each(function(d, rowIndex){
2866 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2867 html = d.data[this.displayField];
2872 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2873 value = d.data[this.valueField];
2882 if(this.value == d.data[this.valueField]){
2883 option['selected'] = true;
2886 var opt = this.inputEl().createChild(option);
2888 this.ios_options.push({
2895 this.inputEl().on('change', function(){
2896 this.fireEvent('select', this);
2901 clearIOSView: function()
2903 this.inputEl().dom.innerHTML = '';
2905 this.ios_options = [];
2908 setIOSValue: function(v)
2912 if(!this.ios_options){
2916 Roo.each(this.ios_options, function(opts){
2918 opts.el.dom.removeAttribute('selected');
2920 if(opts.data[this.valueField] != v){
2924 opts.el.dom.setAttribute('selected', true);
2930 * @cfg {Boolean} grow
2934 * @cfg {Number} growMin
2938 * @cfg {Number} growMax
2947 Roo.apply(Roo.bootstrap.ComboBox, {
2951 cls: 'modal-header',
2973 cls: 'list-group-item',
2977 cls: 'roo-combobox-list-group-item-value'
2981 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2995 listItemCheckbox : {
2997 cls: 'list-group-item',
3001 cls: 'roo-combobox-list-group-item-value'
3005 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3021 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3026 cls: 'modal-footer',
3034 cls: 'col-xs-6 text-left',
3037 cls: 'btn btn-danger roo-touch-view-cancel',
3043 cls: 'col-xs-6 text-right',
3046 cls: 'btn btn-success roo-touch-view-ok',
3057 Roo.apply(Roo.bootstrap.ComboBox, {
3059 touchViewTemplate : {
3061 cls: 'modal fade roo-combobox-touch-view',
3065 cls: 'modal-dialog',
3066 style : 'position:fixed', // we have to fix position....
3070 cls: 'modal-content',
3072 Roo.bootstrap.ComboBox.header,
3073 Roo.bootstrap.ComboBox.body,
3074 Roo.bootstrap.ComboBox.footer