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 false
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',
341 // element that contains real text value.. (when hidden is used..)
343 getAutoCreate : function()
348 * Render classic select for iso
351 if(Roo.isIOS && this.useNativeIOS){
352 cfg = this.getAutoCreateNativeIOS();
360 if(Roo.isTouch && this.mobileTouchView){
361 cfg = this.getAutoCreateTouchView();
369 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
370 if(this.name == 'info_year_invest_id_display_name'){
371 Roo.log('cfg.................................................');
378 * ComboBox with tickable selections
381 var align = this.labelAlign || this.parentLabelAlign();
384 cls : 'form-group roo-combobox-tickable' //input-group
387 var btn_text_select = '';
388 var btn_text_done = '';
389 var btn_text_cancel = '';
391 if (this.btn_text_show) {
392 btn_text_select = 'Select';
393 btn_text_done = 'Done';
394 btn_text_cancel = 'Cancel';
399 cls : 'tickable-buttons',
404 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
405 //html : this.triggerText
406 html: btn_text_select
412 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
420 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
422 html: btn_text_cancel
430 cls: 'roo-select2-search-field-input'
436 Roo.each(buttons.cn, function(c){
438 c.cls += ' btn-' + _this.size;
441 if (_this.disabled) {
452 cls: 'form-hidden-field'
456 cls: 'roo-select2-choices',
460 cls: 'roo-select2-search-field',
471 cls: 'roo-select2-container input-group roo-select2-container-multi',
476 // cls: 'typeahead typeahead-long dropdown-menu',
477 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
482 if(this.hasFeedback && !this.allowBlank){
486 cls: 'glyphicon form-control-feedback'
489 combobox.cn.push(feedback);
493 if (align ==='left' && this.fieldLabel.length) {
495 cfg.cls += ' roo-form-group-label-left';
500 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
501 tooltip : 'This field is required'
506 cls : 'control-label',
507 html : this.fieldLabel
519 var labelCfg = cfg.cn[1];
520 var contentCfg = cfg.cn[2];
523 if(this.indicatorpos == 'right'){
529 cls : 'control-label',
533 html : this.fieldLabel
537 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
538 tooltip : 'This field is required'
553 labelCfg = cfg.cn[0];
554 contentCfg = cfg.cn[1];
558 if(this.labelWidth > 12){
559 labelCfg.style = "width: " + this.labelWidth + 'px';
562 if(this.labelWidth < 13 && this.labelmd == 0){
563 this.labelmd = this.labelWidth;
566 if(this.labellg > 0){
567 labelCfg.cls += ' col-lg-' + this.labellg;
568 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
571 if(this.labelmd > 0){
572 labelCfg.cls += ' col-md-' + this.labelmd;
573 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
576 if(this.labelsm > 0){
577 labelCfg.cls += ' col-sm-' + this.labelsm;
578 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
581 if(this.labelxs > 0){
582 labelCfg.cls += ' col-xs-' + this.labelxs;
583 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
587 } else if ( this.fieldLabel.length) {
588 // Roo.log(" label");
592 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
593 tooltip : 'This field is required'
597 //cls : 'input-group-addon',
598 html : this.fieldLabel
606 if(this.indicatorpos == 'right'){
611 //cls : 'input-group-addon',
615 html : this.fieldLabel
619 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
620 tooltip : 'This field is required'
635 // Roo.log(" no label && no align");
642 ['xs','sm','md','lg'].map(function(size){
643 if (settings[size]) {
644 cfg.cls += ' col-' + size + '-' + settings[size];
652 _initEventsCalled : false,
655 initEvents: function()
657 if (this._initEventsCalled) { // as we call render... prevent looping...
660 this._initEventsCalled = true;
663 throw "can not find store for combo";
666 this.store = Roo.factory(this.store, Roo.data);
668 // if we are building from html. then this element is so complex, that we can not really
669 // use the rendered HTML.
670 // so we have to trash and replace the previous code.
671 if (Roo.XComponent.build_from_html) {
673 // remove this element....
674 var e = this.el.dom, k=0;
675 while (e ) { e = e.previousSibling; ++k;}
680 this.rendered = false;
682 this.render(this.parent().getChildContainer(true), k);
688 if(Roo.isIOS && this.useNativeIOS){
697 if(Roo.isTouch && this.mobileTouchView){
698 this.initTouchView();
703 this.initTickableEvents();
707 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
711 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
713 this.hiddenField.dom.value =
714 this.hiddenValue !== undefined ? this.hiddenValue :
715 this.value !== undefined ? this.value : '';
717 // prevent input submission
718 this.el.dom.removeAttribute('name');
719 this.hiddenField.dom.setAttribute('name', this.hiddenName);
724 // this.el.dom.setAttribute('autocomplete', 'off');
727 var cls = 'x-combo-list';
729 //this.list = new Roo.Layer({
730 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
736 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
737 _this.list.setWidth(lw);
740 this.list.on('mouseover', this.onViewOver, this);
741 this.list.on('mousemove', this.onViewMove, this);
743 this.list.on('scroll', this.onViewScroll, this);
746 this.list.swallowEvent('mousewheel');
747 this.assetHeight = 0;
750 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
751 this.assetHeight += this.header.getHeight();
754 this.innerList = this.list.createChild({cls:cls+'-inner'});
755 this.innerList.on('mouseover', this.onViewOver, this);
756 this.innerList.on('mousemove', this.onViewMove, this);
757 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
759 if(this.allowBlank && !this.pageSize && !this.disableClear){
760 this.footer = this.list.createChild({cls:cls+'-ft'});
761 this.pageTb = new Roo.Toolbar(this.footer);
765 this.footer = this.list.createChild({cls:cls+'-ft'});
766 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
767 {pageSize: this.pageSize});
771 if (this.pageTb && this.allowBlank && !this.disableClear) {
773 this.pageTb.add(new Roo.Toolbar.Fill(), {
774 cls: 'x-btn-icon x-btn-clear',
780 _this.onSelect(false, -1);
785 this.assetHeight += this.footer.getHeight();
790 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
793 this.view = new Roo.View(this.list, this.tpl, {
794 singleSelect:true, store: this.store, selectedClass: this.selectedClass
796 //this.view.wrapEl.setDisplayed(false);
797 this.view.on('click', this.onViewClick, this);
801 this.store.on('beforeload', this.onBeforeLoad, this);
802 this.store.on('load', this.onLoad, this);
803 this.store.on('loadexception', this.onLoadException, this);
806 this.resizer = new Roo.Resizable(this.list, {
807 pinned:true, handles:'se'
809 this.resizer.on('resize', function(r, w, h){
810 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
812 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
813 this.restrictHeight();
815 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
819 this.editable = true;
820 this.setEditable(false);
825 if (typeof(this.events.add.listeners) != 'undefined') {
827 this.addicon = this.wrap.createChild(
828 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
830 this.addicon.on('click', function(e) {
831 this.fireEvent('add', this);
834 if (typeof(this.events.edit.listeners) != 'undefined') {
836 this.editicon = this.wrap.createChild(
837 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
839 this.editicon.setStyle('margin-left', '40px');
841 this.editicon.on('click', function(e) {
843 // we fire even if inothing is selected..
844 this.fireEvent('edit', this, this.lastData );
850 this.keyNav = new Roo.KeyNav(this.inputEl(), {
852 this.inKeyMode = true;
856 "down" : function(e){
857 if(!this.isExpanded()){
858 this.onTriggerClick();
860 this.inKeyMode = true;
865 "enter" : function(e){
866 // this.onViewClick();
870 if(this.fireEvent("specialkey", this, e)){
871 this.onViewClick(false);
884 if(this.fireEvent("specialkey", this, e)){
885 this.onViewClick(false);
893 doRelay : function(foo, bar, hname){
894 if(hname == 'down' || this.scope.isExpanded()){
895 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
904 this.queryDelay = Math.max(this.queryDelay || 10,
905 this.mode == 'local' ? 10 : 250);
908 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
911 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
913 if(this.editable !== false){
914 this.inputEl().on("keyup", this.onKeyUp, this);
916 if(this.forceSelection){
917 this.inputEl().on('blur', this.doForce, this);
921 this.choices = this.el.select('ul.roo-select2-choices', true).first();
922 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
926 initTickableEvents: function()
932 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
934 this.hiddenField.dom.value =
935 this.hiddenValue !== undefined ? this.hiddenValue :
936 this.value !== undefined ? this.value : '';
938 // prevent input submission
939 this.el.dom.removeAttribute('name');
940 this.hiddenField.dom.setAttribute('name', this.hiddenName);
945 // this.list = this.el.select('ul.dropdown-menu',true).first();
947 this.choices = this.el.select('ul.roo-select2-choices', true).first();
948 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
949 if(this.triggerList){
950 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
953 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
954 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
956 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
957 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
959 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
960 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
962 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
963 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
964 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
967 this.cancelBtn.hide();
972 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
973 _this.list.setWidth(lw);
976 this.list.on('mouseover', this.onViewOver, this);
977 this.list.on('mousemove', this.onViewMove, this);
979 this.list.on('scroll', this.onViewScroll, this);
982 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>';
985 this.view = new Roo.View(this.list, this.tpl, {
986 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
989 //this.view.wrapEl.setDisplayed(false);
990 this.view.on('click', this.onViewClick, this);
994 this.store.on('beforeload', this.onBeforeLoad, this);
995 this.store.on('load', this.onLoad, this);
996 this.store.on('loadexception', this.onLoadException, this);
999 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
1001 this.inKeyMode = true;
1005 "down" : function(e){
1006 this.inKeyMode = true;
1010 "enter" : function(e){
1011 if(this.fireEvent("specialkey", this, e)){
1012 this.onViewClick(false);
1018 "esc" : function(e){
1019 this.onTickableFooterButtonClick(e, false, false);
1022 "tab" : function(e){
1023 this.fireEvent("specialkey", this, e);
1025 this.onTickableFooterButtonClick(e, false, false);
1032 doRelay : function(e, fn, key){
1033 if(this.scope.isExpanded()){
1034 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1043 this.queryDelay = Math.max(this.queryDelay || 10,
1044 this.mode == 'local' ? 10 : 250);
1047 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1050 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1053 if(this.editable !== false){
1054 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1057 this.indicator = this.indicatorEl();
1060 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1061 this.indicator.hide();
1066 onDestroy : function(){
1068 this.view.setStore(null);
1069 this.view.el.removeAllListeners();
1070 this.view.el.remove();
1071 this.view.purgeListeners();
1074 this.list.dom.innerHTML = '';
1078 this.store.un('beforeload', this.onBeforeLoad, this);
1079 this.store.un('load', this.onLoad, this);
1080 this.store.un('loadexception', this.onLoadException, this);
1082 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1086 fireKey : function(e){
1087 if(e.isNavKeyPress() && !this.list.isVisible()){
1088 this.fireEvent("specialkey", this, e);
1093 onResize: function(w, h){
1094 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1096 // if(typeof w != 'number'){
1097 // // we do not handle it!?!?
1100 // var tw = this.trigger.getWidth();
1101 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1102 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1104 // this.inputEl().setWidth( this.adjustWidth('input', x));
1106 // //this.trigger.setStyle('left', x+'px');
1108 // if(this.list && this.listWidth === undefined){
1109 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1110 // this.list.setWidth(lw);
1111 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1119 * Allow or prevent the user from directly editing the field text. If false is passed,
1120 * the user will only be able to select from the items defined in the dropdown list. This method
1121 * is the runtime equivalent of setting the 'editable' config option at config time.
1122 * @param {Boolean} value True to allow the user to directly edit the field text
1124 setEditable : function(value){
1125 if(value == this.editable){
1128 this.editable = value;
1130 this.inputEl().dom.setAttribute('readOnly', true);
1131 this.inputEl().on('mousedown', this.onTriggerClick, this);
1132 this.inputEl().addClass('x-combo-noedit');
1134 this.inputEl().dom.setAttribute('readOnly', false);
1135 this.inputEl().un('mousedown', this.onTriggerClick, this);
1136 this.inputEl().removeClass('x-combo-noedit');
1142 onBeforeLoad : function(combo,opts){
1147 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1149 this.restrictHeight();
1150 this.selectedIndex = -1;
1154 onLoad : function(){
1156 this.hasQuery = false;
1162 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1163 this.loading.hide();
1166 if(this.store.getCount() > 0){
1168 this.restrictHeight();
1169 if(this.lastQuery == this.allQuery){
1170 if(this.editable && !this.tickable){
1171 this.inputEl().dom.select();
1175 !this.selectByValue(this.value, true) &&
1178 !this.store.lastOptions ||
1179 typeof(this.store.lastOptions.add) == 'undefined' ||
1180 this.store.lastOptions.add != true
1183 this.select(0, true);
1189 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1190 this.taTask.delay(this.typeAheadDelay);
1194 this.onEmptyResults();
1200 onLoadException : function()
1202 this.hasQuery = false;
1204 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1205 this.loading.hide();
1208 if(this.tickable && this.editable){
1213 // only causes errors at present
1214 //Roo.log(this.store.reader.jsonData);
1215 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1217 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1223 onTypeAhead : function(){
1224 if(this.store.getCount() > 0){
1225 var r = this.store.getAt(0);
1226 var newValue = r.data[this.displayField];
1227 var len = newValue.length;
1228 var selStart = this.getRawValue().length;
1230 if(selStart != len){
1231 this.setRawValue(newValue);
1232 this.selectText(selStart, newValue.length);
1238 onSelect : function(record, index){
1240 if(this.fireEvent('beforeselect', this, record, index) !== false){
1242 this.setFromData(index > -1 ? record.data : false);
1245 this.fireEvent('select', this, record, index);
1250 * Returns the currently selected field value or empty string if no value is set.
1251 * @return {String} value The selected value
1253 getValue : function()
1255 if(Roo.isIOS && this.useNativeIOS){
1256 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1260 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1263 if(this.valueField){
1264 return typeof this.value != 'undefined' ? this.value : '';
1266 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1270 getRawValue : function()
1272 if(Roo.isIOS && this.useNativeIOS){
1273 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1276 var v = this.inputEl().getValue();
1282 * Clears any text/value currently set in the field
1284 clearValue : function(){
1286 if(this.hiddenField){
1287 this.hiddenField.dom.value = '';
1290 this.setRawValue('');
1291 this.lastSelectionText = '';
1292 this.lastData = false;
1294 var close = this.closeTriggerEl();
1305 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1306 * will be displayed in the field. If the value does not match the data value of an existing item,
1307 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1308 * Otherwise the field will be blank (although the value will still be set).
1309 * @param {String} value The value to match
1311 setValue : function(v)
1313 if(Roo.isIOS && this.useNativeIOS){
1314 this.setIOSValue(v);
1324 if(this.valueField){
1325 var r = this.findRecord(this.valueField, v);
1327 text = r.data[this.displayField];
1328 }else if(this.valueNotFoundText !== undefined){
1329 text = this.valueNotFoundText;
1332 this.lastSelectionText = text;
1333 if(this.hiddenField){
1334 this.hiddenField.dom.value = v;
1336 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1339 var close = this.closeTriggerEl();
1342 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1348 * @property {Object} the last set data for the element
1353 * Sets the value of the field based on a object which is related to the record format for the store.
1354 * @param {Object} value the value to set as. or false on reset?
1356 setFromData : function(o){
1363 var dv = ''; // display value
1364 var vv = ''; // value value..
1366 if (this.displayField) {
1367 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1369 // this is an error condition!!!
1370 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1373 if(this.valueField){
1374 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1377 var close = this.closeTriggerEl();
1380 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1383 if(this.hiddenField){
1384 this.hiddenField.dom.value = vv;
1386 this.lastSelectionText = dv;
1387 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1391 // no hidden field.. - we store the value in 'value', but still display
1392 // display field!!!!
1393 this.lastSelectionText = dv;
1394 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1402 // overridden so that last data is reset..
1409 this.setValue(this.originalValue);
1410 //this.clearInvalid();
1411 this.lastData = false;
1413 this.view.clearSelections();
1419 findRecord : function(prop, value){
1421 if(this.store.getCount() > 0){
1422 this.store.each(function(r){
1423 if(r.data[prop] == value){
1435 // returns hidden if it's set..
1436 if (!this.rendered) {return ''};
1437 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1441 onViewMove : function(e, t){
1442 this.inKeyMode = false;
1446 onViewOver : function(e, t){
1447 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1450 var item = this.view.findItemFromChild(t);
1453 var index = this.view.indexOf(item);
1454 this.select(index, false);
1459 onViewClick : function(view, doFocus, el, e)
1461 var index = this.view.getSelectedIndexes()[0];
1463 var r = this.store.getAt(index);
1467 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1474 Roo.each(this.tickItems, function(v,k){
1476 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1478 _this.tickItems.splice(k, 1);
1480 if(typeof(e) == 'undefined' && view == false){
1481 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1493 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1494 this.tickItems.push(r.data);
1497 if(typeof(e) == 'undefined' && view == false){
1498 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1505 this.onSelect(r, index);
1507 if(doFocus !== false && !this.blockFocus){
1508 this.inputEl().focus();
1513 restrictHeight : function(){
1514 //this.innerList.dom.style.height = '';
1515 //var inner = this.innerList.dom;
1516 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1517 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1518 //this.list.beginUpdate();
1519 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1520 this.list.alignTo(this.inputEl(), this.listAlign);
1521 this.list.alignTo(this.inputEl(), this.listAlign);
1522 //this.list.endUpdate();
1526 onEmptyResults : function(){
1528 if(this.tickable && this.editable){
1529 this.restrictHeight();
1537 * Returns true if the dropdown list is expanded, else false.
1539 isExpanded : function(){
1540 return this.list.isVisible();
1544 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1545 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1546 * @param {String} value The data value of the item to select
1547 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1548 * selected item if it is not currently in view (defaults to true)
1549 * @return {Boolean} True if the value matched an item in the list, else false
1551 selectByValue : function(v, scrollIntoView){
1552 if(v !== undefined && v !== null){
1553 var r = this.findRecord(this.valueField || this.displayField, v);
1555 this.select(this.store.indexOf(r), scrollIntoView);
1563 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1564 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1565 * @param {Number} index The zero-based index of the list item to select
1566 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1567 * selected item if it is not currently in view (defaults to true)
1569 select : function(index, scrollIntoView){
1570 this.selectedIndex = index;
1571 this.view.select(index);
1572 if(scrollIntoView !== false){
1573 var el = this.view.getNode(index);
1575 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1578 this.list.scrollChildIntoView(el, false);
1584 selectNext : function(){
1585 var ct = this.store.getCount();
1587 if(this.selectedIndex == -1){
1589 }else if(this.selectedIndex < ct-1){
1590 this.select(this.selectedIndex+1);
1596 selectPrev : function(){
1597 var ct = this.store.getCount();
1599 if(this.selectedIndex == -1){
1601 }else if(this.selectedIndex != 0){
1602 this.select(this.selectedIndex-1);
1608 onKeyUp : function(e){
1609 if(this.editable !== false && !e.isSpecialKey()){
1610 this.lastKey = e.getKey();
1611 this.dqTask.delay(this.queryDelay);
1616 validateBlur : function(){
1617 return !this.list || !this.list.isVisible();
1621 initQuery : function(){
1623 var v = this.getRawValue();
1625 if(this.tickable && this.editable){
1626 v = this.tickableInputEl().getValue();
1633 doForce : function(){
1634 if(this.inputEl().dom.value.length > 0){
1635 this.inputEl().dom.value =
1636 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1642 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1643 * query allowing the query action to be canceled if needed.
1644 * @param {String} query The SQL query to execute
1645 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1646 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1647 * saved in the current store (defaults to false)
1649 doQuery : function(q, forceAll){
1651 if(q === undefined || q === null){
1660 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1665 forceAll = qe.forceAll;
1666 if(forceAll === true || (q.length >= this.minChars)){
1668 this.hasQuery = true;
1670 if(this.lastQuery != q || this.alwaysQuery){
1672 if(this.mode == 'local'){
1673 this.selectedIndex = -1;
1675 this.store.clearFilter();
1678 if(this.specialFilter){
1679 this.fireEvent('specialfilter', this);
1684 this.store.filter(this.displayField, q);
1687 this.store.fireEvent("datachanged", this.store);
1694 this.store.baseParams[this.queryParam] = q;
1696 var options = {params : this.getParams(q)};
1700 options.params.start = this.page * this.pageSize;
1703 this.store.load(options);
1706 * this code will make the page width larger, at the beginning, the list not align correctly,
1707 * we should expand the list on onLoad
1713 this.selectedIndex = -1;
1718 this.loadNext = false;
1722 getParams : function(q){
1724 //p[this.queryParam] = q;
1728 p.limit = this.pageSize;
1734 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1736 collapse : function(){
1737 if(!this.isExpanded()){
1743 this.hasFocus = false;
1747 this.cancelBtn.hide();
1748 this.trigger.show();
1751 this.tickableInputEl().dom.value = '';
1752 this.tickableInputEl().blur();
1757 Roo.get(document).un('mousedown', this.collapseIf, this);
1758 Roo.get(document).un('mousewheel', this.collapseIf, this);
1759 if (!this.editable) {
1760 Roo.get(document).un('keydown', this.listKeyPress, this);
1762 this.fireEvent('collapse', this);
1768 collapseIf : function(e){
1769 var in_combo = e.within(this.el);
1770 var in_list = e.within(this.list);
1771 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1773 if (in_combo || in_list || is_list) {
1774 //e.stopPropagation();
1779 this.onTickableFooterButtonClick(e, false, false);
1787 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1789 expand : function(){
1791 if(this.isExpanded() || !this.hasFocus){
1795 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1796 this.list.setWidth(lw);
1802 this.restrictHeight();
1806 this.tickItems = Roo.apply([], this.item);
1809 this.cancelBtn.show();
1810 this.trigger.hide();
1813 this.tickableInputEl().focus();
1818 Roo.get(document).on('mousedown', this.collapseIf, this);
1819 Roo.get(document).on('mousewheel', this.collapseIf, this);
1820 if (!this.editable) {
1821 Roo.get(document).on('keydown', this.listKeyPress, this);
1824 this.fireEvent('expand', this);
1828 // Implements the default empty TriggerField.onTriggerClick function
1829 onTriggerClick : function(e)
1831 Roo.log('trigger click');
1833 if(this.disabled || !this.triggerList){
1838 this.loadNext = false;
1840 if(this.isExpanded()){
1842 if (!this.blockFocus) {
1843 this.inputEl().focus();
1847 this.hasFocus = true;
1848 if(this.triggerAction == 'all') {
1849 this.doQuery(this.allQuery, true);
1851 this.doQuery(this.getRawValue());
1853 if (!this.blockFocus) {
1854 this.inputEl().focus();
1859 onTickableTriggerClick : function(e)
1866 this.loadNext = false;
1867 this.hasFocus = true;
1869 if(this.triggerAction == 'all') {
1870 this.doQuery(this.allQuery, true);
1872 this.doQuery(this.getRawValue());
1876 onSearchFieldClick : function(e)
1878 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1879 this.onTickableFooterButtonClick(e, false, false);
1883 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1888 this.loadNext = false;
1889 this.hasFocus = true;
1891 if(this.triggerAction == 'all') {
1892 this.doQuery(this.allQuery, true);
1894 this.doQuery(this.getRawValue());
1898 listKeyPress : function(e)
1900 //Roo.log('listkeypress');
1901 // scroll to first matching element based on key pres..
1902 if (e.isSpecialKey()) {
1905 var k = String.fromCharCode(e.getKey()).toUpperCase();
1908 var csel = this.view.getSelectedNodes();
1909 var cselitem = false;
1911 var ix = this.view.indexOf(csel[0]);
1912 cselitem = this.store.getAt(ix);
1913 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1919 this.store.each(function(v) {
1921 // start at existing selection.
1922 if (cselitem.id == v.id) {
1928 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1929 match = this.store.indexOf(v);
1935 if (match === false) {
1936 return true; // no more action?
1939 this.view.select(match);
1940 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1941 sn.scrollIntoView(sn.dom.parentNode, false);
1944 onViewScroll : function(e, t){
1946 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){
1950 this.hasQuery = true;
1952 this.loading = this.list.select('.loading', true).first();
1954 if(this.loading === null){
1955 this.list.createChild({
1957 cls: 'loading roo-select2-more-results roo-select2-active',
1958 html: 'Loading more results...'
1961 this.loading = this.list.select('.loading', true).first();
1963 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1965 this.loading.hide();
1968 this.loading.show();
1973 this.loadNext = true;
1975 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1980 addItem : function(o)
1982 var dv = ''; // display value
1984 if (this.displayField) {
1985 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1987 // this is an error condition!!!
1988 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1995 var choice = this.choices.createChild({
1997 cls: 'roo-select2-search-choice',
2006 cls: 'roo-select2-search-choice-close',
2011 }, this.searchField);
2013 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2015 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2023 this.inputEl().dom.value = '';
2028 onRemoveItem : function(e, _self, o)
2032 this.lastItem = Roo.apply([], this.item);
2034 var index = this.item.indexOf(o.data) * 1;
2037 Roo.log('not this item?!');
2041 this.item.splice(index, 1);
2046 this.fireEvent('remove', this, e);
2052 syncValue : function()
2054 if(!this.item.length){
2061 Roo.each(this.item, function(i){
2062 if(_this.valueField){
2063 value.push(i[_this.valueField]);
2070 this.value = value.join(',');
2072 if(this.hiddenField){
2073 this.hiddenField.dom.value = this.value;
2076 this.store.fireEvent("datachanged", this.store);
2081 clearItem : function()
2089 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2097 if(this.tickable && !Roo.isTouch){
2098 this.view.refresh();
2102 inputEl: function ()
2104 if(Roo.isIOS && this.useNativeIOS){
2105 return this.el.select('select.roo-ios-select', true).first();
2108 if(Roo.isTouch && this.mobileTouchView){
2109 return this.el.select('input.form-control',true).first();
2113 return this.searchField;
2116 return this.el.select('input.form-control',true).first();
2119 onTickableFooterButtonClick : function(e, btn, el)
2123 this.lastItem = Roo.apply([], this.item);
2125 if(btn && btn.name == 'cancel'){
2126 this.tickItems = Roo.apply([], this.item);
2135 Roo.each(this.tickItems, function(o){
2143 validate : function()
2145 var v = this.getRawValue();
2148 v = this.getValue();
2151 if(this.disabled || this.allowBlank || v.length){
2160 tickableInputEl : function()
2162 if(!this.tickable || !this.editable){
2163 return this.inputEl();
2166 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2170 getAutoCreateTouchView : function()
2175 cls: 'form-group' //input-group
2181 type : this.inputType,
2182 cls : 'form-control x-combo-noedit',
2183 autocomplete: 'new-password',
2184 placeholder : this.placeholder || '',
2189 input.name = this.name;
2193 input.cls += ' input-' + this.size;
2196 if (this.disabled) {
2197 input.disabled = true;
2208 inputblock.cls += ' input-group';
2210 inputblock.cn.unshift({
2212 cls : 'input-group-addon',
2217 if(this.removable && !this.multiple){
2218 inputblock.cls += ' roo-removable';
2220 inputblock.cn.push({
2223 cls : 'roo-combo-removable-btn close'
2227 if(this.hasFeedback && !this.allowBlank){
2229 inputblock.cls += ' has-feedback';
2231 inputblock.cn.push({
2233 cls: 'glyphicon form-control-feedback'
2240 inputblock.cls += (this.before) ? '' : ' input-group';
2242 inputblock.cn.push({
2244 cls : 'input-group-addon',
2255 cls: 'form-hidden-field'
2269 cls: 'form-hidden-field'
2273 cls: 'roo-select2-choices',
2277 cls: 'roo-select2-search-field',
2290 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2296 if(!this.multiple && this.showToggleBtn){
2303 if (this.caret != false) {
2306 cls: 'fa fa-' + this.caret
2313 cls : 'input-group-addon btn dropdown-toggle',
2318 cls: 'combobox-clear',
2332 combobox.cls += ' roo-select2-container-multi';
2335 var align = this.labelAlign || this.parentLabelAlign();
2337 if (align ==='left' && this.fieldLabel.length) {
2342 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2343 tooltip : 'This field is required'
2347 cls : 'control-label',
2348 html : this.fieldLabel
2359 var labelCfg = cfg.cn[1];
2360 var contentCfg = cfg.cn[2];
2363 if(this.indicatorpos == 'right'){
2367 cls : 'control-label',
2368 html : this.fieldLabel,
2372 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2373 tooltip : 'This field is required'
2386 labelCfg = cfg.cn[0];
2387 contentCfg = cfg.cn[2];
2389 if(this.labelWidth > 12){
2390 labelCfg.style = "width: " + this.labelWidth + 'px';
2393 if(this.labelWidth < 13 && this.labelmd == 0){
2394 this.labelmd = this.labelWidth;
2397 if(this.labellg > 0){
2398 labelCfg.cls += ' col-lg-' + this.labellg;
2399 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2402 if(this.labelmd > 0){
2403 labelCfg.cls += ' col-md-' + this.labelmd;
2404 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2407 if(this.labelsm > 0){
2408 labelCfg.cls += ' col-sm-' + this.labelsm;
2409 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2412 if(this.labelxs > 0){
2413 labelCfg.cls += ' col-xs-' + this.labelxs;
2414 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2418 } else if ( this.fieldLabel.length) {
2422 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2423 tooltip : 'This field is required'
2427 cls : 'control-label',
2428 html : this.fieldLabel
2439 if(this.indicatorpos == 'right'){
2443 cls : 'control-label',
2444 html : this.fieldLabel,
2448 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2449 tooltip : 'This field is required'
2466 var settings = this;
2468 ['xs','sm','md','lg'].map(function(size){
2469 if (settings[size]) {
2470 cfg.cls += ' col-' + size + '-' + settings[size];
2477 initTouchView : function()
2479 this.renderTouchView();
2481 this.touchViewEl.on('scroll', function(){
2482 this.el.dom.scrollTop = 0;
2485 this.originalValue = this.getValue();
2487 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2489 this.inputEl().on("click", this.showTouchView, this);
2490 if (this.triggerEl) {
2491 this.triggerEl.on("click", this.showTouchView, this);
2495 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2496 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2498 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2500 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2501 this.store.on('load', this.onTouchViewLoad, this);
2502 this.store.on('loadexception', this.onTouchViewLoadException, this);
2504 if(this.hiddenName){
2506 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2508 this.hiddenField.dom.value =
2509 this.hiddenValue !== undefined ? this.hiddenValue :
2510 this.value !== undefined ? this.value : '';
2512 this.el.dom.removeAttribute('name');
2513 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2517 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2518 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2521 if(this.removable && !this.multiple){
2522 var close = this.closeTriggerEl();
2524 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2525 close.on('click', this.removeBtnClick, this, close);
2529 * fix the bug in Safari iOS8
2531 this.inputEl().on("focus", function(e){
2532 document.activeElement.blur();
2540 renderTouchView : function()
2542 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2543 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2545 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2546 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2548 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2549 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2550 this.touchViewBodyEl.setStyle('overflow', 'auto');
2552 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2553 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2555 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2556 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2560 showTouchView : function()
2566 this.touchViewHeaderEl.hide();
2568 if(this.modalTitle.length){
2569 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2570 this.touchViewHeaderEl.show();
2573 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2574 this.touchViewEl.show();
2576 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2577 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2578 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2580 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2582 if(this.modalTitle.length){
2583 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2586 this.touchViewBodyEl.setHeight(bodyHeight);
2590 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2592 this.touchViewEl.addClass('in');
2595 this.doTouchViewQuery();
2599 hideTouchView : function()
2601 this.touchViewEl.removeClass('in');
2605 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2607 this.touchViewEl.setStyle('display', 'none');
2612 setTouchViewValue : function()
2619 Roo.each(this.tickItems, function(o){
2624 this.hideTouchView();
2627 doTouchViewQuery : function()
2636 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2640 if(!this.alwaysQuery || this.mode == 'local'){
2641 this.onTouchViewLoad();
2648 onTouchViewBeforeLoad : function(combo,opts)
2654 onTouchViewLoad : function()
2656 if(this.store.getCount() < 1){
2657 this.onTouchViewEmptyResults();
2661 this.clearTouchView();
2663 var rawValue = this.getRawValue();
2665 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2667 this.tickItems = [];
2669 this.store.data.each(function(d, rowIndex){
2670 var row = this.touchViewListGroup.createChild(template);
2672 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2673 row.addClass(d.data.cls);
2676 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2679 html : d.data[this.displayField]
2682 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2683 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2686 row.removeClass('selected');
2687 if(!this.multiple && this.valueField &&
2688 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2691 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2692 row.addClass('selected');
2695 if(this.multiple && this.valueField &&
2696 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2700 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2701 this.tickItems.push(d.data);
2704 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2708 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2710 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2712 if(this.modalTitle.length){
2713 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2716 var listHeight = this.touchViewListGroup.getHeight();
2720 if(firstChecked && listHeight > bodyHeight){
2721 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2726 onTouchViewLoadException : function()
2728 this.hideTouchView();
2731 onTouchViewEmptyResults : function()
2733 this.clearTouchView();
2735 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2737 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2741 clearTouchView : function()
2743 this.touchViewListGroup.dom.innerHTML = '';
2746 onTouchViewClick : function(e, el, o)
2751 var rowIndex = o.rowIndex;
2753 var r = this.store.getAt(rowIndex);
2755 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2758 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2759 c.dom.removeAttribute('checked');
2762 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2764 this.setFromData(r.data);
2766 var close = this.closeTriggerEl();
2772 this.hideTouchView();
2774 this.fireEvent('select', this, r, rowIndex);
2779 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2780 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2781 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2785 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2786 this.addItem(r.data);
2787 this.tickItems.push(r.data);
2791 getAutoCreateNativeIOS : function()
2794 cls: 'form-group' //input-group,
2799 cls : 'roo-ios-select'
2803 combobox.name = this.name;
2806 if (this.disabled) {
2807 combobox.disabled = true;
2810 var settings = this;
2812 ['xs','sm','md','lg'].map(function(size){
2813 if (settings[size]) {
2814 cfg.cls += ' col-' + size + '-' + settings[size];
2824 initIOSView : function()
2826 this.store.on('load', this.onIOSViewLoad, this);
2831 onIOSViewLoad : function()
2833 if(this.store.getCount() < 1){
2837 this.clearIOSView();
2839 if(this.allowBlank) {
2841 var default_text = '-- SELECT --';
2843 var opt = this.inputEl().createChild({
2850 o[this.valueField] = 0;
2851 o[this.displayField] = default_text;
2853 this.ios_options.push({
2860 this.store.data.each(function(d, rowIndex){
2864 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2865 html = d.data[this.displayField];
2870 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2871 value = d.data[this.valueField];
2880 if(this.value == d.data[this.valueField]){
2881 option['selected'] = true;
2884 var opt = this.inputEl().createChild(option);
2886 this.ios_options.push({
2893 this.inputEl().on('change', function(){
2894 this.fireEvent('select', this);
2899 clearIOSView: function()
2901 this.inputEl().dom.innerHTML = '';
2903 this.ios_options = [];
2906 setIOSValue: function(v)
2910 if(!this.ios_options){
2914 Roo.each(this.ios_options, function(opts){
2916 opts.el.dom.removeAttribute('selected');
2918 if(opts.data[this.valueField] != v){
2922 opts.el.dom.setAttribute('selected', true);
2928 * @cfg {Boolean} grow
2932 * @cfg {Number} growMin
2936 * @cfg {Number} growMax
2945 Roo.apply(Roo.bootstrap.ComboBox, {
2949 cls: 'modal-header',
2971 cls: 'list-group-item',
2975 cls: 'roo-combobox-list-group-item-value'
2979 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2993 listItemCheckbox : {
2995 cls: 'list-group-item',
2999 cls: 'roo-combobox-list-group-item-value'
3003 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3019 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3024 cls: 'modal-footer',
3032 cls: 'col-xs-6 text-left',
3035 cls: 'btn btn-danger roo-touch-view-cancel',
3041 cls: 'col-xs-6 text-right',
3044 cls: 'btn btn-success roo-touch-view-ok',
3055 Roo.apply(Roo.bootstrap.ComboBox, {
3057 touchViewTemplate : {
3059 cls: 'modal fade roo-combobox-touch-view',
3063 cls: 'modal-dialog',
3064 style : 'position:fixed', // we have to fix position....
3068 cls: 'modal-content',
3070 Roo.bootstrap.ComboBox.header,
3071 Roo.bootstrap.ComboBox.body,
3072 Roo.bootstrap.ComboBox.footer