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
604 if(this.indicatorpos == 'right'){
605 Roo.log('hidden name:'+this.hiddenName);
612 html : this.fieldLabel
616 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
617 tooltip : 'This field is required'
628 // Roo.log(" no label && no align");
635 ['xs','sm','md','lg'].map(function(size){
636 if (settings[size]) {
637 cfg.cls += ' col-' + size + '-' + settings[size];
645 _initEventsCalled : false,
648 initEvents: function()
650 if (this._initEventsCalled) { // as we call render... prevent looping...
653 this._initEventsCalled = true;
656 throw "can not find store for combo";
659 this.store = Roo.factory(this.store, Roo.data);
660 this.store.parent = this;
662 // if we are building from html. then this element is so complex, that we can not really
663 // use the rendered HTML.
664 // so we have to trash and replace the previous code.
665 if (Roo.XComponent.build_from_html) {
667 // remove this element....
668 var e = this.el.dom, k=0;
669 while (e ) { e = e.previousSibling; ++k;}
674 this.rendered = false;
676 this.render(this.parent().getChildContainer(true), k);
682 if(Roo.isIOS && this.useNativeIOS){
691 if(Roo.isTouch && this.mobileTouchView){
692 this.initTouchView();
697 this.initTickableEvents();
701 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
705 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
707 this.hiddenField.dom.value =
708 this.hiddenValue !== undefined ? this.hiddenValue :
709 this.value !== undefined ? this.value : '';
711 // prevent input submission
712 this.el.dom.removeAttribute('name');
713 this.hiddenField.dom.setAttribute('name', this.hiddenName);
718 // this.el.dom.setAttribute('autocomplete', 'off');
721 var cls = 'x-combo-list';
723 //this.list = new Roo.Layer({
724 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
730 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
731 _this.list.setWidth(lw);
734 this.list.on('mouseover', this.onViewOver, this);
735 this.list.on('mousemove', this.onViewMove, this);
737 this.list.on('scroll', this.onViewScroll, this);
740 this.list.swallowEvent('mousewheel');
741 this.assetHeight = 0;
744 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
745 this.assetHeight += this.header.getHeight();
748 this.innerList = this.list.createChild({cls:cls+'-inner'});
749 this.innerList.on('mouseover', this.onViewOver, this);
750 this.innerList.on('mousemove', this.onViewMove, this);
751 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
753 if(this.allowBlank && !this.pageSize && !this.disableClear){
754 this.footer = this.list.createChild({cls:cls+'-ft'});
755 this.pageTb = new Roo.Toolbar(this.footer);
759 this.footer = this.list.createChild({cls:cls+'-ft'});
760 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
761 {pageSize: this.pageSize});
765 if (this.pageTb && this.allowBlank && !this.disableClear) {
767 this.pageTb.add(new Roo.Toolbar.Fill(), {
768 cls: 'x-btn-icon x-btn-clear',
774 _this.onSelect(false, -1);
779 this.assetHeight += this.footer.getHeight();
784 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
787 this.view = new Roo.View(this.list, this.tpl, {
788 singleSelect:true, store: this.store, selectedClass: this.selectedClass
790 //this.view.wrapEl.setDisplayed(false);
791 this.view.on('click', this.onViewClick, this);
794 this.store.on('beforeload', this.onBeforeLoad, this);
795 this.store.on('load', this.onLoad, this);
796 this.store.on('loadexception', this.onLoadException, this);
799 this.resizer = new Roo.Resizable(this.list, {
800 pinned:true, handles:'se'
802 this.resizer.on('resize', function(r, w, h){
803 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
805 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
806 this.restrictHeight();
808 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
812 this.editable = true;
813 this.setEditable(false);
818 if (typeof(this.events.add.listeners) != 'undefined') {
820 this.addicon = this.wrap.createChild(
821 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
823 this.addicon.on('click', function(e) {
824 this.fireEvent('add', this);
827 if (typeof(this.events.edit.listeners) != 'undefined') {
829 this.editicon = this.wrap.createChild(
830 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
832 this.editicon.setStyle('margin-left', '40px');
834 this.editicon.on('click', function(e) {
836 // we fire even if inothing is selected..
837 this.fireEvent('edit', this, this.lastData );
843 this.keyNav = new Roo.KeyNav(this.inputEl(), {
845 this.inKeyMode = true;
849 "down" : function(e){
850 if(!this.isExpanded()){
851 this.onTriggerClick();
853 this.inKeyMode = true;
858 "enter" : function(e){
859 // this.onViewClick();
863 if(this.fireEvent("specialkey", this, e)){
864 this.onViewClick(false);
877 if(this.fireEvent("specialkey", this, e)){
878 this.onViewClick(false);
886 doRelay : function(foo, bar, hname){
887 if(hname == 'down' || this.scope.isExpanded()){
888 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
897 this.queryDelay = Math.max(this.queryDelay || 10,
898 this.mode == 'local' ? 10 : 250);
901 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
904 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
906 if(this.editable !== false){
907 this.inputEl().on("keyup", this.onKeyUp, this);
909 if(this.forceSelection){
910 this.inputEl().on('blur', this.doForce, this);
914 this.choices = this.el.select('ul.roo-select2-choices', true).first();
915 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
919 initTickableEvents: function()
925 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
927 this.hiddenField.dom.value =
928 this.hiddenValue !== undefined ? this.hiddenValue :
929 this.value !== undefined ? this.value : '';
931 // prevent input submission
932 this.el.dom.removeAttribute('name');
933 this.hiddenField.dom.setAttribute('name', this.hiddenName);
938 // this.list = this.el.select('ul.dropdown-menu',true).first();
940 this.choices = this.el.select('ul.roo-select2-choices', true).first();
941 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
942 if(this.triggerList){
943 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
946 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
947 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
949 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
950 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
952 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
953 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
955 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
956 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
957 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
960 this.cancelBtn.hide();
965 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
966 _this.list.setWidth(lw);
969 this.list.on('mouseover', this.onViewOver, this);
970 this.list.on('mousemove', this.onViewMove, this);
972 this.list.on('scroll', this.onViewScroll, this);
975 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
978 this.view = new Roo.View(this.list, this.tpl, {
979 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
982 //this.view.wrapEl.setDisplayed(false);
983 this.view.on('click', this.onViewClick, this);
987 this.store.on('beforeload', this.onBeforeLoad, this);
988 this.store.on('load', this.onLoad, this);
989 this.store.on('loadexception', this.onLoadException, this);
992 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
994 this.inKeyMode = true;
998 "down" : function(e){
999 this.inKeyMode = true;
1003 "enter" : function(e){
1004 if(this.fireEvent("specialkey", this, e)){
1005 this.onViewClick(false);
1011 "esc" : function(e){
1012 this.onTickableFooterButtonClick(e, false, false);
1015 "tab" : function(e){
1016 this.fireEvent("specialkey", this, e);
1018 this.onTickableFooterButtonClick(e, false, false);
1025 doRelay : function(e, fn, key){
1026 if(this.scope.isExpanded()){
1027 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1036 this.queryDelay = Math.max(this.queryDelay || 10,
1037 this.mode == 'local' ? 10 : 250);
1040 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1043 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1046 if(this.editable !== false){
1047 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1050 this.indicator = this.indicatorEl();
1053 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1054 this.indicator.hide();
1059 onDestroy : function(){
1061 this.view.setStore(null);
1062 this.view.el.removeAllListeners();
1063 this.view.el.remove();
1064 this.view.purgeListeners();
1067 this.list.dom.innerHTML = '';
1071 this.store.un('beforeload', this.onBeforeLoad, this);
1072 this.store.un('load', this.onLoad, this);
1073 this.store.un('loadexception', this.onLoadException, this);
1075 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1079 fireKey : function(e){
1080 if(e.isNavKeyPress() && !this.list.isVisible()){
1081 this.fireEvent("specialkey", this, e);
1086 onResize: function(w, h){
1087 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1089 // if(typeof w != 'number'){
1090 // // we do not handle it!?!?
1093 // var tw = this.trigger.getWidth();
1094 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1095 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1097 // this.inputEl().setWidth( this.adjustWidth('input', x));
1099 // //this.trigger.setStyle('left', x+'px');
1101 // if(this.list && this.listWidth === undefined){
1102 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1103 // this.list.setWidth(lw);
1104 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1112 * Allow or prevent the user from directly editing the field text. If false is passed,
1113 * the user will only be able to select from the items defined in the dropdown list. This method
1114 * is the runtime equivalent of setting the 'editable' config option at config time.
1115 * @param {Boolean} value True to allow the user to directly edit the field text
1117 setEditable : function(value){
1118 if(value == this.editable){
1121 this.editable = value;
1123 this.inputEl().dom.setAttribute('readOnly', true);
1124 this.inputEl().on('mousedown', this.onTriggerClick, this);
1125 this.inputEl().addClass('x-combo-noedit');
1127 this.inputEl().dom.setAttribute('readOnly', false);
1128 this.inputEl().un('mousedown', this.onTriggerClick, this);
1129 this.inputEl().removeClass('x-combo-noedit');
1135 onBeforeLoad : function(combo,opts){
1140 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1142 this.restrictHeight();
1143 this.selectedIndex = -1;
1147 onLoad : function(){
1149 this.hasQuery = false;
1155 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1156 this.loading.hide();
1159 if(this.store.getCount() > 0){
1162 this.restrictHeight();
1163 if(this.lastQuery == this.allQuery){
1164 if(this.editable && !this.tickable){
1165 this.inputEl().dom.select();
1169 !this.selectByValue(this.value, true) &&
1172 !this.store.lastOptions ||
1173 typeof(this.store.lastOptions.add) == 'undefined' ||
1174 this.store.lastOptions.add != true
1177 this.select(0, true);
1183 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1184 this.taTask.delay(this.typeAheadDelay);
1188 this.onEmptyResults();
1194 onLoadException : function()
1196 this.hasQuery = false;
1198 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1199 this.loading.hide();
1202 if(this.tickable && this.editable){
1207 // only causes errors at present
1208 //Roo.log(this.store.reader.jsonData);
1209 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1211 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1217 onTypeAhead : function(){
1218 if(this.store.getCount() > 0){
1219 var r = this.store.getAt(0);
1220 var newValue = r.data[this.displayField];
1221 var len = newValue.length;
1222 var selStart = this.getRawValue().length;
1224 if(selStart != len){
1225 this.setRawValue(newValue);
1226 this.selectText(selStart, newValue.length);
1232 onSelect : function(record, index){
1234 if(this.fireEvent('beforeselect', this, record, index) !== false){
1236 this.setFromData(index > -1 ? record.data : false);
1239 this.fireEvent('select', this, record, index);
1244 * Returns the currently selected field value or empty string if no value is set.
1245 * @return {String} value The selected value
1247 getValue : function()
1249 if(Roo.isIOS && this.useNativeIOS){
1250 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1254 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1257 if(this.valueField){
1258 return typeof this.value != 'undefined' ? this.value : '';
1260 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1264 getRawValue : function()
1266 if(Roo.isIOS && this.useNativeIOS){
1267 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1270 var v = this.inputEl().getValue();
1276 * Clears any text/value currently set in the field
1278 clearValue : function(){
1280 if(this.hiddenField){
1281 this.hiddenField.dom.value = '';
1284 this.setRawValue('');
1285 this.lastSelectionText = '';
1286 this.lastData = false;
1288 var close = this.closeTriggerEl();
1299 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1300 * will be displayed in the field. If the value does not match the data value of an existing item,
1301 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1302 * Otherwise the field will be blank (although the value will still be set).
1303 * @param {String} value The value to match
1305 setValue : function(v)
1307 if(Roo.isIOS && this.useNativeIOS){
1308 this.setIOSValue(v);
1318 if(this.valueField){
1319 var r = this.findRecord(this.valueField, v);
1321 text = r.data[this.displayField];
1322 }else if(this.valueNotFoundText !== undefined){
1323 text = this.valueNotFoundText;
1326 this.lastSelectionText = text;
1327 if(this.hiddenField){
1328 this.hiddenField.dom.value = v;
1330 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1333 var close = this.closeTriggerEl();
1336 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1342 * @property {Object} the last set data for the element
1347 * Sets the value of the field based on a object which is related to the record format for the store.
1348 * @param {Object} value the value to set as. or false on reset?
1350 setFromData : function(o){
1357 var dv = ''; // display value
1358 var vv = ''; // value value..
1360 if (this.displayField) {
1361 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1363 // this is an error condition!!!
1364 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1367 if(this.valueField){
1368 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1371 var close = this.closeTriggerEl();
1374 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1377 if(this.hiddenField){
1378 this.hiddenField.dom.value = vv;
1380 this.lastSelectionText = dv;
1381 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1385 // no hidden field.. - we store the value in 'value', but still display
1386 // display field!!!!
1387 this.lastSelectionText = dv;
1388 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1396 // overridden so that last data is reset..
1403 this.setValue(this.originalValue);
1404 //this.clearInvalid();
1405 this.lastData = false;
1407 this.view.clearSelections();
1413 findRecord : function(prop, value){
1415 if(this.store.getCount() > 0){
1416 this.store.each(function(r){
1417 if(r.data[prop] == value){
1429 // returns hidden if it's set..
1430 if (!this.rendered) {return ''};
1431 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1435 onViewMove : function(e, t){
1436 this.inKeyMode = false;
1440 onViewOver : function(e, t){
1441 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1444 var item = this.view.findItemFromChild(t);
1447 var index = this.view.indexOf(item);
1448 this.select(index, false);
1453 onViewClick : function(view, doFocus, el, e)
1455 var index = this.view.getSelectedIndexes()[0];
1457 var r = this.store.getAt(index);
1461 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1468 Roo.each(this.tickItems, function(v,k){
1470 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1472 _this.tickItems.splice(k, 1);
1474 if(typeof(e) == 'undefined' && view == false){
1475 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1487 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1488 this.tickItems.push(r.data);
1491 if(typeof(e) == 'undefined' && view == false){
1492 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1499 this.onSelect(r, index);
1501 if(doFocus !== false && !this.blockFocus){
1502 this.inputEl().focus();
1507 restrictHeight : function(){
1508 //this.innerList.dom.style.height = '';
1509 //var inner = this.innerList.dom;
1510 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1511 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1512 //this.list.beginUpdate();
1513 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1514 this.list.alignTo(this.inputEl(), this.listAlign);
1515 this.list.alignTo(this.inputEl(), this.listAlign);
1516 //this.list.endUpdate();
1520 onEmptyResults : function(){
1522 if(this.tickable && this.editable){
1523 this.restrictHeight();
1531 * Returns true if the dropdown list is expanded, else false.
1533 isExpanded : function(){
1534 return this.list.isVisible();
1538 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1539 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1540 * @param {String} value The data value of the item to select
1541 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1542 * selected item if it is not currently in view (defaults to true)
1543 * @return {Boolean} True if the value matched an item in the list, else false
1545 selectByValue : function(v, scrollIntoView){
1546 if(v !== undefined && v !== null){
1547 var r = this.findRecord(this.valueField || this.displayField, v);
1549 this.select(this.store.indexOf(r), scrollIntoView);
1557 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1558 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1559 * @param {Number} index The zero-based index of the list item to select
1560 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1561 * selected item if it is not currently in view (defaults to true)
1563 select : function(index, scrollIntoView){
1564 this.selectedIndex = index;
1565 this.view.select(index);
1566 if(scrollIntoView !== false){
1567 var el = this.view.getNode(index);
1569 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1572 this.list.scrollChildIntoView(el, false);
1578 selectNext : function(){
1579 var ct = this.store.getCount();
1581 if(this.selectedIndex == -1){
1583 }else if(this.selectedIndex < ct-1){
1584 this.select(this.selectedIndex+1);
1590 selectPrev : function(){
1591 var ct = this.store.getCount();
1593 if(this.selectedIndex == -1){
1595 }else if(this.selectedIndex != 0){
1596 this.select(this.selectedIndex-1);
1602 onKeyUp : function(e){
1603 if(this.editable !== false && !e.isSpecialKey()){
1604 this.lastKey = e.getKey();
1605 this.dqTask.delay(this.queryDelay);
1610 validateBlur : function(){
1611 return !this.list || !this.list.isVisible();
1615 initQuery : function(){
1617 var v = this.getRawValue();
1619 if(this.tickable && this.editable){
1620 v = this.tickableInputEl().getValue();
1627 doForce : function(){
1628 if(this.inputEl().dom.value.length > 0){
1629 this.inputEl().dom.value =
1630 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1636 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1637 * query allowing the query action to be canceled if needed.
1638 * @param {String} query The SQL query to execute
1639 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1640 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1641 * saved in the current store (defaults to false)
1643 doQuery : function(q, forceAll){
1645 if(q === undefined || q === null){
1654 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1659 forceAll = qe.forceAll;
1660 if(forceAll === true || (q.length >= this.minChars)){
1662 this.hasQuery = true;
1664 if(this.lastQuery != q || this.alwaysQuery){
1666 if(this.mode == 'local'){
1667 this.selectedIndex = -1;
1669 this.store.clearFilter();
1672 if(this.specialFilter){
1673 this.fireEvent('specialfilter', this);
1678 this.store.filter(this.displayField, q);
1681 this.store.fireEvent("datachanged", this.store);
1688 this.store.baseParams[this.queryParam] = q;
1690 var options = {params : this.getParams(q)};
1694 options.params.start = this.page * this.pageSize;
1697 this.store.load(options);
1700 * this code will make the page width larger, at the beginning, the list not align correctly,
1701 * we should expand the list on onLoad
1707 this.selectedIndex = -1;
1712 this.loadNext = false;
1716 getParams : function(q){
1718 //p[this.queryParam] = q;
1722 p.limit = this.pageSize;
1728 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1730 collapse : function(){
1731 if(!this.isExpanded()){
1737 this.hasFocus = false;
1741 this.cancelBtn.hide();
1742 this.trigger.show();
1745 this.tickableInputEl().dom.value = '';
1746 this.tickableInputEl().blur();
1751 Roo.get(document).un('mousedown', this.collapseIf, this);
1752 Roo.get(document).un('mousewheel', this.collapseIf, this);
1753 if (!this.editable) {
1754 Roo.get(document).un('keydown', this.listKeyPress, this);
1756 this.fireEvent('collapse', this);
1762 collapseIf : function(e){
1763 var in_combo = e.within(this.el);
1764 var in_list = e.within(this.list);
1765 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1767 if (in_combo || in_list || is_list) {
1768 //e.stopPropagation();
1773 this.onTickableFooterButtonClick(e, false, false);
1781 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1783 expand : function(){
1785 if(this.isExpanded() || !this.hasFocus){
1789 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1790 this.list.setWidth(lw);
1796 this.restrictHeight();
1800 this.tickItems = Roo.apply([], this.item);
1803 this.cancelBtn.show();
1804 this.trigger.hide();
1807 this.tickableInputEl().focus();
1812 Roo.get(document).on('mousedown', this.collapseIf, this);
1813 Roo.get(document).on('mousewheel', this.collapseIf, this);
1814 if (!this.editable) {
1815 Roo.get(document).on('keydown', this.listKeyPress, this);
1818 this.fireEvent('expand', this);
1822 // Implements the default empty TriggerField.onTriggerClick function
1823 onTriggerClick : function(e)
1825 Roo.log('trigger click');
1827 if(this.disabled || !this.triggerList){
1832 this.loadNext = false;
1834 if(this.isExpanded()){
1836 if (!this.blockFocus) {
1837 this.inputEl().focus();
1841 this.hasFocus = true;
1842 if(this.triggerAction == 'all') {
1843 this.doQuery(this.allQuery, true);
1845 this.doQuery(this.getRawValue());
1847 if (!this.blockFocus) {
1848 this.inputEl().focus();
1853 onTickableTriggerClick : function(e)
1860 this.loadNext = false;
1861 this.hasFocus = true;
1863 if(this.triggerAction == 'all') {
1864 this.doQuery(this.allQuery, true);
1866 this.doQuery(this.getRawValue());
1870 onSearchFieldClick : function(e)
1872 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1873 this.onTickableFooterButtonClick(e, false, false);
1877 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1882 this.loadNext = false;
1883 this.hasFocus = true;
1885 if(this.triggerAction == 'all') {
1886 this.doQuery(this.allQuery, true);
1888 this.doQuery(this.getRawValue());
1892 listKeyPress : function(e)
1894 //Roo.log('listkeypress');
1895 // scroll to first matching element based on key pres..
1896 if (e.isSpecialKey()) {
1899 var k = String.fromCharCode(e.getKey()).toUpperCase();
1902 var csel = this.view.getSelectedNodes();
1903 var cselitem = false;
1905 var ix = this.view.indexOf(csel[0]);
1906 cselitem = this.store.getAt(ix);
1907 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1913 this.store.each(function(v) {
1915 // start at existing selection.
1916 if (cselitem.id == v.id) {
1922 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1923 match = this.store.indexOf(v);
1929 if (match === false) {
1930 return true; // no more action?
1933 this.view.select(match);
1934 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1935 sn.scrollIntoView(sn.dom.parentNode, false);
1938 onViewScroll : function(e, t){
1940 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){
1944 this.hasQuery = true;
1946 this.loading = this.list.select('.loading', true).first();
1948 if(this.loading === null){
1949 this.list.createChild({
1951 cls: 'loading roo-select2-more-results roo-select2-active',
1952 html: 'Loading more results...'
1955 this.loading = this.list.select('.loading', true).first();
1957 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1959 this.loading.hide();
1962 this.loading.show();
1967 this.loadNext = true;
1969 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1974 addItem : function(o)
1976 var dv = ''; // display value
1978 if (this.displayField) {
1979 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1981 // this is an error condition!!!
1982 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1989 var choice = this.choices.createChild({
1991 cls: 'roo-select2-search-choice',
2000 cls: 'roo-select2-search-choice-close fa fa-times',
2005 }, this.searchField);
2007 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2009 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2017 this.inputEl().dom.value = '';
2022 onRemoveItem : function(e, _self, o)
2026 this.lastItem = Roo.apply([], this.item);
2028 var index = this.item.indexOf(o.data) * 1;
2031 Roo.log('not this item?!');
2035 this.item.splice(index, 1);
2040 this.fireEvent('remove', this, e);
2046 syncValue : function()
2048 if(!this.item.length){
2055 Roo.each(this.item, function(i){
2056 if(_this.valueField){
2057 value.push(i[_this.valueField]);
2064 this.value = value.join(',');
2066 if(this.hiddenField){
2067 this.hiddenField.dom.value = this.value;
2070 this.store.fireEvent("datachanged", this.store);
2075 clearItem : function()
2083 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2091 if(this.tickable && !Roo.isTouch){
2092 this.view.refresh();
2096 inputEl: function ()
2098 if(Roo.isIOS && this.useNativeIOS){
2099 return this.el.select('select.roo-ios-select', true).first();
2102 if(Roo.isTouch && this.mobileTouchView){
2103 return this.el.select('input.form-control',true).first();
2107 return this.searchField;
2110 return this.el.select('input.form-control',true).first();
2113 onTickableFooterButtonClick : function(e, btn, el)
2117 this.lastItem = Roo.apply([], this.item);
2119 if(btn && btn.name == 'cancel'){
2120 this.tickItems = Roo.apply([], this.item);
2129 Roo.each(this.tickItems, function(o){
2137 validate : function()
2139 var v = this.getRawValue();
2142 v = this.getValue();
2145 if(this.disabled || this.allowBlank || v.length){
2154 tickableInputEl : function()
2156 if(!this.tickable || !this.editable){
2157 return this.inputEl();
2160 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2164 getAutoCreateTouchView : function()
2169 cls: 'form-group' //input-group
2175 type : this.inputType,
2176 cls : 'form-control x-combo-noedit',
2177 autocomplete: 'new-password',
2178 placeholder : this.placeholder || '',
2183 input.name = this.name;
2187 input.cls += ' input-' + this.size;
2190 if (this.disabled) {
2191 input.disabled = true;
2202 inputblock.cls += ' input-group';
2204 inputblock.cn.unshift({
2206 cls : 'input-group-addon',
2211 if(this.removable && !this.multiple){
2212 inputblock.cls += ' roo-removable';
2214 inputblock.cn.push({
2217 cls : 'roo-combo-removable-btn close'
2221 if(this.hasFeedback && !this.allowBlank){
2223 inputblock.cls += ' has-feedback';
2225 inputblock.cn.push({
2227 cls: 'glyphicon form-control-feedback'
2234 inputblock.cls += (this.before) ? '' : ' input-group';
2236 inputblock.cn.push({
2238 cls : 'input-group-addon',
2249 cls: 'form-hidden-field'
2263 cls: 'form-hidden-field'
2267 cls: 'roo-select2-choices',
2271 cls: 'roo-select2-search-field',
2284 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2290 if(!this.multiple && this.showToggleBtn){
2297 if (this.caret != false) {
2300 cls: 'fa fa-' + this.caret
2307 cls : 'input-group-addon btn dropdown-toggle',
2312 cls: 'combobox-clear',
2326 combobox.cls += ' roo-select2-container-multi';
2329 var align = this.labelAlign || this.parentLabelAlign();
2331 if (align ==='left' && this.fieldLabel.length) {
2336 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2337 tooltip : 'This field is required'
2341 cls : 'control-label',
2342 html : this.fieldLabel
2353 var labelCfg = cfg.cn[1];
2354 var contentCfg = cfg.cn[2];
2357 if(this.indicatorpos == 'right'){
2361 cls : 'control-label',
2362 html : this.fieldLabel,
2366 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2367 tooltip : 'This field is required'
2380 labelCfg = cfg.cn[0];
2381 contentCfg = cfg.cn[2];
2383 if(this.labelWidth > 12){
2384 labelCfg.style = "width: " + this.labelWidth + 'px';
2387 if(this.labelWidth < 13 && this.labelmd == 0){
2388 this.labelmd = this.labelWidth;
2391 if(this.labellg > 0){
2392 labelCfg.cls += ' col-lg-' + this.labellg;
2393 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2396 if(this.labelmd > 0){
2397 labelCfg.cls += ' col-md-' + this.labelmd;
2398 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2401 if(this.labelsm > 0){
2402 labelCfg.cls += ' col-sm-' + this.labelsm;
2403 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2406 if(this.labelxs > 0){
2407 labelCfg.cls += ' col-xs-' + this.labelxs;
2408 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2412 } else if ( this.fieldLabel.length) {
2416 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2417 tooltip : 'This field is required'
2421 cls : 'control-label',
2422 html : this.fieldLabel
2433 if(this.indicatorpos == 'right'){
2437 cls : 'control-label',
2438 html : this.fieldLabel,
2442 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2443 tooltip : 'This field is required'
2460 var settings = this;
2462 ['xs','sm','md','lg'].map(function(size){
2463 if (settings[size]) {
2464 cfg.cls += ' col-' + size + '-' + settings[size];
2471 initTouchView : function()
2473 this.renderTouchView();
2475 this.touchViewEl.on('scroll', function(){
2476 this.el.dom.scrollTop = 0;
2479 this.originalValue = this.getValue();
2481 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2483 this.inputEl().on("click", this.showTouchView, this);
2484 if (this.triggerEl) {
2485 this.triggerEl.on("click", this.showTouchView, this);
2489 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2490 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2492 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2494 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2495 this.store.on('load', this.onTouchViewLoad, this);
2496 this.store.on('loadexception', this.onTouchViewLoadException, this);
2498 if(this.hiddenName){
2500 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2502 this.hiddenField.dom.value =
2503 this.hiddenValue !== undefined ? this.hiddenValue :
2504 this.value !== undefined ? this.value : '';
2506 this.el.dom.removeAttribute('name');
2507 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2511 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2512 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2515 if(this.removable && !this.multiple){
2516 var close = this.closeTriggerEl();
2518 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2519 close.on('click', this.removeBtnClick, this, close);
2523 * fix the bug in Safari iOS8
2525 this.inputEl().on("focus", function(e){
2526 document.activeElement.blur();
2534 renderTouchView : function()
2536 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2537 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2539 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2540 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2542 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2543 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2544 this.touchViewBodyEl.setStyle('overflow', 'auto');
2546 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2547 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2549 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2550 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2554 showTouchView : function()
2560 this.touchViewHeaderEl.hide();
2562 if(this.modalTitle.length){
2563 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2564 this.touchViewHeaderEl.show();
2567 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2568 this.touchViewEl.show();
2570 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2571 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2572 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2574 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2576 if(this.modalTitle.length){
2577 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2580 this.touchViewBodyEl.setHeight(bodyHeight);
2584 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2586 this.touchViewEl.addClass('in');
2589 this.doTouchViewQuery();
2593 hideTouchView : function()
2595 this.touchViewEl.removeClass('in');
2599 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2601 this.touchViewEl.setStyle('display', 'none');
2606 setTouchViewValue : function()
2613 Roo.each(this.tickItems, function(o){
2618 this.hideTouchView();
2621 doTouchViewQuery : function()
2630 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2634 if(!this.alwaysQuery || this.mode == 'local'){
2635 this.onTouchViewLoad();
2642 onTouchViewBeforeLoad : function(combo,opts)
2648 onTouchViewLoad : function()
2650 if(this.store.getCount() < 1){
2651 this.onTouchViewEmptyResults();
2655 this.clearTouchView();
2657 var rawValue = this.getRawValue();
2659 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2661 this.tickItems = [];
2663 this.store.data.each(function(d, rowIndex){
2664 var row = this.touchViewListGroup.createChild(template);
2666 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2667 row.addClass(d.data.cls);
2670 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2673 html : d.data[this.displayField]
2676 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2677 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2680 row.removeClass('selected');
2681 if(!this.multiple && this.valueField &&
2682 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2685 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2686 row.addClass('selected');
2689 if(this.multiple && this.valueField &&
2690 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2694 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2695 this.tickItems.push(d.data);
2698 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2702 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2704 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2706 if(this.modalTitle.length){
2707 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2710 var listHeight = this.touchViewListGroup.getHeight();
2714 if(firstChecked && listHeight > bodyHeight){
2715 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2720 onTouchViewLoadException : function()
2722 this.hideTouchView();
2725 onTouchViewEmptyResults : function()
2727 this.clearTouchView();
2729 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2731 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2735 clearTouchView : function()
2737 this.touchViewListGroup.dom.innerHTML = '';
2740 onTouchViewClick : function(e, el, o)
2745 var rowIndex = o.rowIndex;
2747 var r = this.store.getAt(rowIndex);
2749 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2752 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2753 c.dom.removeAttribute('checked');
2756 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2758 this.setFromData(r.data);
2760 var close = this.closeTriggerEl();
2766 this.hideTouchView();
2768 this.fireEvent('select', this, r, rowIndex);
2773 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2774 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2775 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2779 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2780 this.addItem(r.data);
2781 this.tickItems.push(r.data);
2785 getAutoCreateNativeIOS : function()
2788 cls: 'form-group' //input-group,
2793 cls : 'roo-ios-select'
2797 combobox.name = this.name;
2800 if (this.disabled) {
2801 combobox.disabled = true;
2804 var settings = this;
2806 ['xs','sm','md','lg'].map(function(size){
2807 if (settings[size]) {
2808 cfg.cls += ' col-' + size + '-' + settings[size];
2818 initIOSView : function()
2820 this.store.on('load', this.onIOSViewLoad, this);
2825 onIOSViewLoad : function()
2827 if(this.store.getCount() < 1){
2831 this.clearIOSView();
2833 if(this.allowBlank) {
2835 var default_text = '-- SELECT --';
2837 var opt = this.inputEl().createChild({
2844 o[this.valueField] = 0;
2845 o[this.displayField] = default_text;
2847 this.ios_options.push({
2854 this.store.data.each(function(d, rowIndex){
2858 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2859 html = d.data[this.displayField];
2864 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2865 value = d.data[this.valueField];
2874 if(this.value == d.data[this.valueField]){
2875 option['selected'] = true;
2878 var opt = this.inputEl().createChild(option);
2880 this.ios_options.push({
2887 this.inputEl().on('change', function(){
2888 this.fireEvent('select', this);
2893 clearIOSView: function()
2895 this.inputEl().dom.innerHTML = '';
2897 this.ios_options = [];
2900 setIOSValue: function(v)
2904 if(!this.ios_options){
2908 Roo.each(this.ios_options, function(opts){
2910 opts.el.dom.removeAttribute('selected');
2912 if(opts.data[this.valueField] != v){
2916 opts.el.dom.setAttribute('selected', true);
2922 * @cfg {Boolean} grow
2926 * @cfg {Number} growMin
2930 * @cfg {Number} growMax
2939 Roo.apply(Roo.bootstrap.ComboBox, {
2943 cls: 'modal-header',
2965 cls: 'list-group-item',
2969 cls: 'roo-combobox-list-group-item-value'
2973 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2987 listItemCheckbox : {
2989 cls: 'list-group-item',
2993 cls: 'roo-combobox-list-group-item-value'
2997 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3013 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3018 cls: 'modal-footer',
3026 cls: 'col-xs-6 text-left',
3029 cls: 'btn btn-danger roo-touch-view-cancel',
3035 cls: 'col-xs-6 text-right',
3038 cls: 'btn btn-success roo-touch-view-ok',
3049 Roo.apply(Roo.bootstrap.ComboBox, {
3051 touchViewTemplate : {
3053 cls: 'modal fade roo-combobox-touch-view',
3057 cls: 'modal-dialog',
3058 style : 'position:fixed', // we have to fix position....
3062 cls: 'modal-content',
3064 Roo.bootstrap.ComboBox.header,
3065 Roo.bootstrap.ComboBox.body,
3066 Roo.bootstrap.ComboBox.footer