7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
20 * Create a new ComboBox.
21 * @param {Object} config Configuration options
23 Roo.bootstrap.ComboBox = function(config){
24 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
28 * Fires when the dropdown list is expanded
29 * @param {Roo.bootstrap.ComboBox} combo This combo box
34 * Fires when the dropdown list is collapsed
35 * @param {Roo.bootstrap.ComboBox} combo This combo box
40 * Fires before a list item is selected. Return false to cancel the selection.
41 * @param {Roo.bootstrap.ComboBox} combo This combo box
42 * @param {Roo.data.Record} record The data record returned from the underlying store
43 * @param {Number} index The index of the selected item in the dropdown list
45 'beforeselect' : true,
48 * Fires when a list item is selected
49 * @param {Roo.bootstrap.ComboBox} combo This combo box
50 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
51 * @param {Number} index The index of the selected item in the dropdown list
56 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
57 * The event object passed has these properties:
58 * @param {Roo.bootstrap.ComboBox} combo This combo box
59 * @param {String} query The query
60 * @param {Boolean} forceAll true to force "all" query
61 * @param {Boolean} cancel true to cancel the query
62 * @param {Object} e The query event object
67 * Fires when the 'add' icon is pressed (add a listener to enable add button)
68 * @param {Roo.bootstrap.ComboBox} combo This combo box
73 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
74 * @param {Roo.bootstrap.ComboBox} combo This combo box
75 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
80 * Fires when the remove value from the combobox array
81 * @param {Roo.bootstrap.ComboBox} combo This combo box
86 * Fires when the remove value from the combobox array
87 * @param {Roo.bootstrap.ComboBox} combo This combo box
91 * @event specialfilter
92 * Fires when specialfilter
93 * @param {Roo.bootstrap.ComboBox} combo This combo box
95 'specialfilter' : true,
98 * Fires when tick the element
99 * @param {Roo.bootstrap.ComboBox} combo This combo box
103 * @event touchviewdisplay
104 * Fires when touch view require special display (default is using displayField)
105 * @param {Roo.bootstrap.ComboBox} combo This combo box
106 * @param {Object} cfg set html .
108 'touchviewdisplay' : true
115 this.selectedIndex = -1;
116 if(this.mode == 'local'){
117 if(config.queryDelay === undefined){
118 this.queryDelay = 10;
120 if(config.minChars === undefined){
126 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
129 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
130 * rendering into an Roo.Editor, defaults to false)
133 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
134 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
137 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
140 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
141 * the dropdown list (defaults to undefined, with no header element)
145 * @cfg {String/Roo.Template} tpl The template to use to render the output
149 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
151 listWidth: undefined,
153 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
154 * mode = 'remote' or 'text' if mode = 'local')
156 displayField: undefined,
159 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
160 * mode = 'remote' or 'value' if mode = 'local').
161 * Note: use of a valueField requires the user make a selection
162 * in order for a value to be mapped.
164 valueField: undefined,
166 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
171 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
172 * field's data value (defaults to the underlying DOM element's name)
174 hiddenName: undefined,
176 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
180 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
182 selectedClass: 'active',
185 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
189 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
190 * anchor positions (defaults to 'tl-bl')
194 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
198 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
199 * query specified by the allQuery config option (defaults to 'query')
201 triggerAction: 'query',
203 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
204 * (defaults to 4, does not apply if editable = false)
208 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
209 * delay (typeAheadDelay) if it matches a known value (defaults to false)
213 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
214 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
218 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
219 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
223 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
224 * when editable = true (defaults to false)
228 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
232 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
233 * when mode = 'remote' (defaults to 'Loading...')
235 loadingText: 'Loading...',
237 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
241 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
245 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
246 * traditional select (defaults to true)
250 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
254 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
258 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
259 * listWidth has a higher value)
263 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
264 * allow the user to set arbitrary text into the field (defaults to false)
266 forceSelection:false,
268 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
269 * if typeAhead = true (defaults to 250)
271 typeAheadDelay : 250,
273 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
274 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
276 valueNotFoundText : undefined,
278 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
283 * @cfg {Boolean} disableClear Disable showing of clear button.
285 disableClear : false,
287 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
292 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
297 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
299 invalidClass : "has-warning",
302 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
304 validClass : "has-success",
307 * @cfg {Boolean} specialFilter (true|false) special filter default false
309 specialFilter : false,
312 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
314 mobileTouchView : true,
317 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
319 useNativeIOS : false,
333 btnPosition : 'right',
335 showToggleBtn : true,
337 emptyResultText: 'Empty',
338 triggerText : 'Select',
340 // element that contains real text value.. (when hidden is used..)
342 getAutoCreate : function()
347 * Render classic select for iso
350 if(Roo.isIOS && this.useNativeIOS){
351 cfg = this.getAutoCreateNativeIOS();
359 if(Roo.isTouch && this.mobileTouchView){
360 cfg = this.getAutoCreateTouchView();
368 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
369 if(this.name == 'info_year_invest_id_display_name'){
370 Roo.log('cfg.................................................');
377 * ComboBox with tickable selections
380 var align = this.labelAlign || this.parentLabelAlign();
383 cls : 'form-group roo-combobox-tickable' //input-group
386 var btn_text_select = '';
387 var btn_text_done = '';
388 var btn_text_cancel = '';
390 if (this.btn_text_show) {
391 btn_text_select = 'Select';
392 btn_text_done = 'Done';
393 btn_text_cancel = 'Cancel';
398 cls : 'tickable-buttons',
403 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
404 //html : this.triggerText
405 html: btn_text_select
411 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
419 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
421 html: btn_text_cancel
429 cls: 'roo-select2-search-field-input'
435 Roo.each(buttons.cn, function(c){
437 c.cls += ' btn-' + _this.size;
440 if (_this.disabled) {
451 cls: 'form-hidden-field'
455 cls: 'roo-select2-choices',
459 cls: 'roo-select2-search-field',
470 cls: 'roo-select2-container input-group roo-select2-container-multi',
475 // cls: 'typeahead typeahead-long dropdown-menu',
476 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
481 if(this.hasFeedback && !this.allowBlank){
485 cls: 'glyphicon form-control-feedback'
488 combobox.cn.push(feedback);
492 if (align ==='left' && this.fieldLabel.length) {
494 cfg.cls += ' roo-form-group-label-left';
499 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
500 tooltip : 'This field is required'
505 cls : 'control-label',
506 html : this.fieldLabel
518 var labelCfg = cfg.cn[1];
519 var contentCfg = cfg.cn[2];
522 if(this.indicatorpos == 'right'){
528 cls : 'control-label',
529 html : this.fieldLabel
534 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
535 tooltip : 'This field is required'
546 labelCfg = cfg.cn[0];
547 contentCfg = cfg.cn[2];
551 if(this.labelWidth > 12){
552 labelCfg.style = "width: " + this.labelWidth + 'px';
555 if(this.labelWidth < 13 && this.labelmd == 0){
556 this.labelmd = this.labelWidth;
559 if(this.labellg > 0){
560 labelCfg.cls += ' col-lg-' + this.labellg;
561 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
564 if(this.labelmd > 0){
565 labelCfg.cls += ' col-md-' + this.labelmd;
566 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
569 if(this.labelsm > 0){
570 labelCfg.cls += ' col-sm-' + this.labelsm;
571 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
574 if(this.labelxs > 0){
575 labelCfg.cls += ' col-xs-' + this.labelxs;
576 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
580 } else if ( this.fieldLabel.length) {
581 // Roo.log(" label");
585 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
586 tooltip : 'This field is required'
590 //cls : 'input-group-addon',
591 html : this.fieldLabel
599 if(this.indicatorpos == 'right'){
604 //cls : 'input-group-addon',
605 html : this.fieldLabel
611 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
612 tooltip : 'This field is required'
623 // Roo.log(" no label && no align");
630 ['xs','sm','md','lg'].map(function(size){
631 if (settings[size]) {
632 cfg.cls += ' col-' + size + '-' + settings[size];
640 _initEventsCalled : false,
643 initEvents: function()
645 if (this._initEventsCalled) { // as we call render... prevent looping...
648 this._initEventsCalled = true;
651 throw "can not find store for combo";
654 this.store = Roo.factory(this.store, Roo.data);
656 // if we are building from html. then this element is so complex, that we can not really
657 // use the rendered HTML.
658 // so we have to trash and replace the previous code.
659 if (Roo.XComponent.build_from_html) {
661 // remove this element....
662 var e = this.el.dom, k=0;
663 while (e ) { e = e.previousSibling; ++k;}
668 this.rendered = false;
670 this.render(this.parent().getChildContainer(true), k);
676 if(Roo.isIOS && this.useNativeIOS){
685 if(Roo.isTouch && this.mobileTouchView){
686 this.initTouchView();
691 this.initTickableEvents();
695 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
699 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
701 this.hiddenField.dom.value =
702 this.hiddenValue !== undefined ? this.hiddenValue :
703 this.value !== undefined ? this.value : '';
705 // prevent input submission
706 this.el.dom.removeAttribute('name');
707 this.hiddenField.dom.setAttribute('name', this.hiddenName);
712 // this.el.dom.setAttribute('autocomplete', 'off');
715 var cls = 'x-combo-list';
717 //this.list = new Roo.Layer({
718 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
724 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
725 _this.list.setWidth(lw);
728 this.list.on('mouseover', this.onViewOver, this);
729 this.list.on('mousemove', this.onViewMove, this);
731 this.list.on('scroll', this.onViewScroll, this);
734 this.list.swallowEvent('mousewheel');
735 this.assetHeight = 0;
738 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
739 this.assetHeight += this.header.getHeight();
742 this.innerList = this.list.createChild({cls:cls+'-inner'});
743 this.innerList.on('mouseover', this.onViewOver, this);
744 this.innerList.on('mousemove', this.onViewMove, this);
745 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
747 if(this.allowBlank && !this.pageSize && !this.disableClear){
748 this.footer = this.list.createChild({cls:cls+'-ft'});
749 this.pageTb = new Roo.Toolbar(this.footer);
753 this.footer = this.list.createChild({cls:cls+'-ft'});
754 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
755 {pageSize: this.pageSize});
759 if (this.pageTb && this.allowBlank && !this.disableClear) {
761 this.pageTb.add(new Roo.Toolbar.Fill(), {
762 cls: 'x-btn-icon x-btn-clear',
768 _this.onSelect(false, -1);
773 this.assetHeight += this.footer.getHeight();
778 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
781 this.view = new Roo.View(this.list, this.tpl, {
782 singleSelect:true, store: this.store, selectedClass: this.selectedClass
784 //this.view.wrapEl.setDisplayed(false);
785 this.view.on('click', this.onViewClick, this);
789 this.store.on('beforeload', this.onBeforeLoad, this);
790 this.store.on('load', this.onLoad, this);
791 this.store.on('loadexception', this.onLoadException, this);
794 this.resizer = new Roo.Resizable(this.list, {
795 pinned:true, handles:'se'
797 this.resizer.on('resize', function(r, w, h){
798 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
800 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
801 this.restrictHeight();
803 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
807 this.editable = true;
808 this.setEditable(false);
813 if (typeof(this.events.add.listeners) != 'undefined') {
815 this.addicon = this.wrap.createChild(
816 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
818 this.addicon.on('click', function(e) {
819 this.fireEvent('add', this);
822 if (typeof(this.events.edit.listeners) != 'undefined') {
824 this.editicon = this.wrap.createChild(
825 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
827 this.editicon.setStyle('margin-left', '40px');
829 this.editicon.on('click', function(e) {
831 // we fire even if inothing is selected..
832 this.fireEvent('edit', this, this.lastData );
838 this.keyNav = new Roo.KeyNav(this.inputEl(), {
840 this.inKeyMode = true;
844 "down" : function(e){
845 if(!this.isExpanded()){
846 this.onTriggerClick();
848 this.inKeyMode = true;
853 "enter" : function(e){
854 // this.onViewClick();
858 if(this.fireEvent("specialkey", this, e)){
859 this.onViewClick(false);
872 if(this.fireEvent("specialkey", this, e)){
873 this.onViewClick(false);
881 doRelay : function(foo, bar, hname){
882 if(hname == 'down' || this.scope.isExpanded()){
883 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
892 this.queryDelay = Math.max(this.queryDelay || 10,
893 this.mode == 'local' ? 10 : 250);
896 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
899 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
901 if(this.editable !== false){
902 this.inputEl().on("keyup", this.onKeyUp, this);
904 if(this.forceSelection){
905 this.inputEl().on('blur', this.doForce, this);
909 this.choices = this.el.select('ul.roo-select2-choices', true).first();
910 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
914 initTickableEvents: function()
920 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
922 this.hiddenField.dom.value =
923 this.hiddenValue !== undefined ? this.hiddenValue :
924 this.value !== undefined ? this.value : '';
926 // prevent input submission
927 this.el.dom.removeAttribute('name');
928 this.hiddenField.dom.setAttribute('name', this.hiddenName);
933 // this.list = this.el.select('ul.dropdown-menu',true).first();
935 this.choices = this.el.select('ul.roo-select2-choices', true).first();
936 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
937 if(this.triggerList){
938 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
941 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
942 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
944 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
945 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
947 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
948 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
950 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
951 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
952 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
955 this.cancelBtn.hide();
960 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
961 _this.list.setWidth(lw);
964 this.list.on('mouseover', this.onViewOver, this);
965 this.list.on('mousemove', this.onViewMove, this);
967 this.list.on('scroll', this.onViewScroll, this);
970 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>';
973 this.view = new Roo.View(this.list, this.tpl, {
974 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
977 //this.view.wrapEl.setDisplayed(false);
978 this.view.on('click', this.onViewClick, this);
982 this.store.on('beforeload', this.onBeforeLoad, this);
983 this.store.on('load', this.onLoad, this);
984 this.store.on('loadexception', this.onLoadException, this);
987 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
989 this.inKeyMode = true;
993 "down" : function(e){
994 this.inKeyMode = true;
998 "enter" : function(e){
999 if(this.fireEvent("specialkey", this, e)){
1000 this.onViewClick(false);
1006 "esc" : function(e){
1007 this.onTickableFooterButtonClick(e, false, false);
1010 "tab" : function(e){
1011 this.fireEvent("specialkey", this, e);
1013 this.onTickableFooterButtonClick(e, false, false);
1020 doRelay : function(e, fn, key){
1021 if(this.scope.isExpanded()){
1022 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1031 this.queryDelay = Math.max(this.queryDelay || 10,
1032 this.mode == 'local' ? 10 : 250);
1035 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1038 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1041 if(this.editable !== false){
1042 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1047 onDestroy : function(){
1049 this.view.setStore(null);
1050 this.view.el.removeAllListeners();
1051 this.view.el.remove();
1052 this.view.purgeListeners();
1055 this.list.dom.innerHTML = '';
1059 this.store.un('beforeload', this.onBeforeLoad, this);
1060 this.store.un('load', this.onLoad, this);
1061 this.store.un('loadexception', this.onLoadException, this);
1063 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1067 fireKey : function(e){
1068 if(e.isNavKeyPress() && !this.list.isVisible()){
1069 this.fireEvent("specialkey", this, e);
1074 onResize: function(w, h){
1075 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1077 // if(typeof w != 'number'){
1078 // // we do not handle it!?!?
1081 // var tw = this.trigger.getWidth();
1082 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1083 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1085 // this.inputEl().setWidth( this.adjustWidth('input', x));
1087 // //this.trigger.setStyle('left', x+'px');
1089 // if(this.list && this.listWidth === undefined){
1090 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1091 // this.list.setWidth(lw);
1092 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1100 * Allow or prevent the user from directly editing the field text. If false is passed,
1101 * the user will only be able to select from the items defined in the dropdown list. This method
1102 * is the runtime equivalent of setting the 'editable' config option at config time.
1103 * @param {Boolean} value True to allow the user to directly edit the field text
1105 setEditable : function(value){
1106 if(value == this.editable){
1109 this.editable = value;
1111 this.inputEl().dom.setAttribute('readOnly', true);
1112 this.inputEl().on('mousedown', this.onTriggerClick, this);
1113 this.inputEl().addClass('x-combo-noedit');
1115 this.inputEl().dom.setAttribute('readOnly', false);
1116 this.inputEl().un('mousedown', this.onTriggerClick, this);
1117 this.inputEl().removeClass('x-combo-noedit');
1123 onBeforeLoad : function(combo,opts){
1128 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1130 this.restrictHeight();
1131 this.selectedIndex = -1;
1135 onLoad : function(){
1137 this.hasQuery = false;
1143 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1144 this.loading.hide();
1147 if(this.store.getCount() > 0){
1149 this.restrictHeight();
1150 if(this.lastQuery == this.allQuery){
1151 if(this.editable && !this.tickable){
1152 this.inputEl().dom.select();
1156 !this.selectByValue(this.value, true) &&
1159 !this.store.lastOptions ||
1160 typeof(this.store.lastOptions.add) == 'undefined' ||
1161 this.store.lastOptions.add != true
1164 this.select(0, true);
1170 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1171 this.taTask.delay(this.typeAheadDelay);
1175 this.onEmptyResults();
1181 onLoadException : function()
1183 this.hasQuery = false;
1185 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1186 this.loading.hide();
1189 if(this.tickable && this.editable){
1194 // only causes errors at present
1195 //Roo.log(this.store.reader.jsonData);
1196 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1198 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1204 onTypeAhead : function(){
1205 if(this.store.getCount() > 0){
1206 var r = this.store.getAt(0);
1207 var newValue = r.data[this.displayField];
1208 var len = newValue.length;
1209 var selStart = this.getRawValue().length;
1211 if(selStart != len){
1212 this.setRawValue(newValue);
1213 this.selectText(selStart, newValue.length);
1219 onSelect : function(record, index){
1221 if(this.fireEvent('beforeselect', this, record, index) !== false){
1223 this.setFromData(index > -1 ? record.data : false);
1226 this.fireEvent('select', this, record, index);
1231 * Returns the currently selected field value or empty string if no value is set.
1232 * @return {String} value The selected value
1234 getValue : function()
1236 if(Roo.isIOS && this.useNativeIOS){
1237 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1241 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1244 if(this.valueField){
1245 return typeof this.value != 'undefined' ? this.value : '';
1247 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1251 getRawValue : function()
1253 if(Roo.isIOS && this.useNativeIOS){
1254 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1257 var v = this.inputEl().getValue();
1263 * Clears any text/value currently set in the field
1265 clearValue : function(){
1267 if(this.hiddenField){
1268 this.hiddenField.dom.value = '';
1271 this.setRawValue('');
1272 this.lastSelectionText = '';
1273 this.lastData = false;
1275 var close = this.closeTriggerEl();
1286 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1287 * will be displayed in the field. If the value does not match the data value of an existing item,
1288 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1289 * Otherwise the field will be blank (although the value will still be set).
1290 * @param {String} value The value to match
1292 setValue : function(v)
1294 if(Roo.isIOS && this.useNativeIOS){
1295 this.setIOSValue(v);
1305 if(this.valueField){
1306 var r = this.findRecord(this.valueField, v);
1308 text = r.data[this.displayField];
1309 }else if(this.valueNotFoundText !== undefined){
1310 text = this.valueNotFoundText;
1313 this.lastSelectionText = text;
1314 if(this.hiddenField){
1315 this.hiddenField.dom.value = v;
1317 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1320 var close = this.closeTriggerEl();
1323 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1329 * @property {Object} the last set data for the element
1334 * Sets the value of the field based on a object which is related to the record format for the store.
1335 * @param {Object} value the value to set as. or false on reset?
1337 setFromData : function(o){
1344 var dv = ''; // display value
1345 var vv = ''; // value value..
1347 if (this.displayField) {
1348 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1350 // this is an error condition!!!
1351 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1354 if(this.valueField){
1355 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1358 var close = this.closeTriggerEl();
1361 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1364 if(this.hiddenField){
1365 this.hiddenField.dom.value = vv;
1367 this.lastSelectionText = dv;
1368 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1372 // no hidden field.. - we store the value in 'value', but still display
1373 // display field!!!!
1374 this.lastSelectionText = dv;
1375 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1383 // overridden so that last data is reset..
1390 this.setValue(this.originalValue);
1391 //this.clearInvalid();
1392 this.lastData = false;
1394 this.view.clearSelections();
1400 findRecord : function(prop, value){
1402 if(this.store.getCount() > 0){
1403 this.store.each(function(r){
1404 if(r.data[prop] == value){
1416 // returns hidden if it's set..
1417 if (!this.rendered) {return ''};
1418 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1422 onViewMove : function(e, t){
1423 this.inKeyMode = false;
1427 onViewOver : function(e, t){
1428 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1431 var item = this.view.findItemFromChild(t);
1434 var index = this.view.indexOf(item);
1435 this.select(index, false);
1440 onViewClick : function(view, doFocus, el, e)
1442 var index = this.view.getSelectedIndexes()[0];
1444 var r = this.store.getAt(index);
1448 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1455 Roo.each(this.tickItems, function(v,k){
1457 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1459 _this.tickItems.splice(k, 1);
1461 if(typeof(e) == 'undefined' && view == false){
1462 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1474 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1475 this.tickItems.push(r.data);
1478 if(typeof(e) == 'undefined' && view == false){
1479 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1486 this.onSelect(r, index);
1488 if(doFocus !== false && !this.blockFocus){
1489 this.inputEl().focus();
1494 restrictHeight : function(){
1495 //this.innerList.dom.style.height = '';
1496 //var inner = this.innerList.dom;
1497 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1498 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1499 //this.list.beginUpdate();
1500 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1501 this.list.alignTo(this.inputEl(), this.listAlign);
1502 this.list.alignTo(this.inputEl(), this.listAlign);
1503 //this.list.endUpdate();
1507 onEmptyResults : function(){
1509 if(this.tickable && this.editable){
1510 this.restrictHeight();
1518 * Returns true if the dropdown list is expanded, else false.
1520 isExpanded : function(){
1521 return this.list.isVisible();
1525 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1526 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1527 * @param {String} value The data value of the item to select
1528 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1529 * selected item if it is not currently in view (defaults to true)
1530 * @return {Boolean} True if the value matched an item in the list, else false
1532 selectByValue : function(v, scrollIntoView){
1533 if(v !== undefined && v !== null){
1534 var r = this.findRecord(this.valueField || this.displayField, v);
1536 this.select(this.store.indexOf(r), scrollIntoView);
1544 * Select an item in the dropdown list by its numeric index in the list. 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 {Number} index The zero-based index of the list 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)
1550 select : function(index, scrollIntoView){
1551 this.selectedIndex = index;
1552 this.view.select(index);
1553 if(scrollIntoView !== false){
1554 var el = this.view.getNode(index);
1556 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1559 this.list.scrollChildIntoView(el, false);
1565 selectNext : function(){
1566 var ct = this.store.getCount();
1568 if(this.selectedIndex == -1){
1570 }else if(this.selectedIndex < ct-1){
1571 this.select(this.selectedIndex+1);
1577 selectPrev : function(){
1578 var ct = this.store.getCount();
1580 if(this.selectedIndex == -1){
1582 }else if(this.selectedIndex != 0){
1583 this.select(this.selectedIndex-1);
1589 onKeyUp : function(e){
1590 if(this.editable !== false && !e.isSpecialKey()){
1591 this.lastKey = e.getKey();
1592 this.dqTask.delay(this.queryDelay);
1597 validateBlur : function(){
1598 return !this.list || !this.list.isVisible();
1602 initQuery : function(){
1604 var v = this.getRawValue();
1606 if(this.tickable && this.editable){
1607 v = this.tickableInputEl().getValue();
1614 doForce : function(){
1615 if(this.inputEl().dom.value.length > 0){
1616 this.inputEl().dom.value =
1617 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1623 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1624 * query allowing the query action to be canceled if needed.
1625 * @param {String} query The SQL query to execute
1626 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1627 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1628 * saved in the current store (defaults to false)
1630 doQuery : function(q, forceAll){
1632 if(q === undefined || q === null){
1641 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1646 forceAll = qe.forceAll;
1647 if(forceAll === true || (q.length >= this.minChars)){
1649 this.hasQuery = true;
1651 if(this.lastQuery != q || this.alwaysQuery){
1653 if(this.mode == 'local'){
1654 this.selectedIndex = -1;
1656 this.store.clearFilter();
1659 if(this.specialFilter){
1660 this.fireEvent('specialfilter', this);
1665 this.store.filter(this.displayField, q);
1668 this.store.fireEvent("datachanged", this.store);
1675 this.store.baseParams[this.queryParam] = q;
1677 var options = {params : this.getParams(q)};
1681 options.params.start = this.page * this.pageSize;
1684 this.store.load(options);
1687 * this code will make the page width larger, at the beginning, the list not align correctly,
1688 * we should expand the list on onLoad
1694 this.selectedIndex = -1;
1699 this.loadNext = false;
1703 getParams : function(q){
1705 //p[this.queryParam] = q;
1709 p.limit = this.pageSize;
1715 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1717 collapse : function(){
1718 if(!this.isExpanded()){
1724 this.hasFocus = false;
1728 this.cancelBtn.hide();
1729 this.trigger.show();
1732 this.tickableInputEl().dom.value = '';
1733 this.tickableInputEl().blur();
1738 Roo.get(document).un('mousedown', this.collapseIf, this);
1739 Roo.get(document).un('mousewheel', this.collapseIf, this);
1740 if (!this.editable) {
1741 Roo.get(document).un('keydown', this.listKeyPress, this);
1743 this.fireEvent('collapse', this);
1749 collapseIf : function(e){
1750 var in_combo = e.within(this.el);
1751 var in_list = e.within(this.list);
1752 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1754 if (in_combo || in_list || is_list) {
1755 //e.stopPropagation();
1760 this.onTickableFooterButtonClick(e, false, false);
1768 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1770 expand : function(){
1772 if(this.isExpanded() || !this.hasFocus){
1776 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1777 this.list.setWidth(lw);
1783 this.restrictHeight();
1787 this.tickItems = Roo.apply([], this.item);
1790 this.cancelBtn.show();
1791 this.trigger.hide();
1794 this.tickableInputEl().focus();
1799 Roo.get(document).on('mousedown', this.collapseIf, this);
1800 Roo.get(document).on('mousewheel', this.collapseIf, this);
1801 if (!this.editable) {
1802 Roo.get(document).on('keydown', this.listKeyPress, this);
1805 this.fireEvent('expand', this);
1809 // Implements the default empty TriggerField.onTriggerClick function
1810 onTriggerClick : function(e)
1812 Roo.log('trigger click');
1814 if(this.disabled || !this.triggerList){
1819 this.loadNext = false;
1821 if(this.isExpanded()){
1823 if (!this.blockFocus) {
1824 this.inputEl().focus();
1828 this.hasFocus = true;
1829 if(this.triggerAction == 'all') {
1830 this.doQuery(this.allQuery, true);
1832 this.doQuery(this.getRawValue());
1834 if (!this.blockFocus) {
1835 this.inputEl().focus();
1840 onTickableTriggerClick : function(e)
1847 this.loadNext = false;
1848 this.hasFocus = true;
1850 if(this.triggerAction == 'all') {
1851 this.doQuery(this.allQuery, true);
1853 this.doQuery(this.getRawValue());
1857 onSearchFieldClick : function(e)
1859 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1860 this.onTickableFooterButtonClick(e, false, false);
1864 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1869 this.loadNext = false;
1870 this.hasFocus = true;
1872 if(this.triggerAction == 'all') {
1873 this.doQuery(this.allQuery, true);
1875 this.doQuery(this.getRawValue());
1879 listKeyPress : function(e)
1881 //Roo.log('listkeypress');
1882 // scroll to first matching element based on key pres..
1883 if (e.isSpecialKey()) {
1886 var k = String.fromCharCode(e.getKey()).toUpperCase();
1889 var csel = this.view.getSelectedNodes();
1890 var cselitem = false;
1892 var ix = this.view.indexOf(csel[0]);
1893 cselitem = this.store.getAt(ix);
1894 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1900 this.store.each(function(v) {
1902 // start at existing selection.
1903 if (cselitem.id == v.id) {
1909 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1910 match = this.store.indexOf(v);
1916 if (match === false) {
1917 return true; // no more action?
1920 this.view.select(match);
1921 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1922 sn.scrollIntoView(sn.dom.parentNode, false);
1925 onViewScroll : function(e, t){
1927 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){
1931 this.hasQuery = true;
1933 this.loading = this.list.select('.loading', true).first();
1935 if(this.loading === null){
1936 this.list.createChild({
1938 cls: 'loading roo-select2-more-results roo-select2-active',
1939 html: 'Loading more results...'
1942 this.loading = this.list.select('.loading', true).first();
1944 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1946 this.loading.hide();
1949 this.loading.show();
1954 this.loadNext = true;
1956 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1961 addItem : function(o)
1963 var dv = ''; // display value
1965 if (this.displayField) {
1966 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1968 // this is an error condition!!!
1969 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1976 var choice = this.choices.createChild({
1978 cls: 'roo-select2-search-choice',
1987 cls: 'roo-select2-search-choice-close',
1992 }, this.searchField);
1994 var close = choice.select('a.roo-select2-search-choice-close', true).first();
1996 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2004 this.inputEl().dom.value = '';
2009 onRemoveItem : function(e, _self, o)
2013 this.lastItem = Roo.apply([], this.item);
2015 var index = this.item.indexOf(o.data) * 1;
2018 Roo.log('not this item?!');
2022 this.item.splice(index, 1);
2027 this.fireEvent('remove', this, e);
2033 syncValue : function()
2035 if(!this.item.length){
2042 Roo.each(this.item, function(i){
2043 if(_this.valueField){
2044 value.push(i[_this.valueField]);
2051 this.value = value.join(',');
2053 if(this.hiddenField){
2054 this.hiddenField.dom.value = this.value;
2057 this.store.fireEvent("datachanged", this.store);
2062 clearItem : function()
2070 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2078 if(this.tickable && !Roo.isTouch){
2079 this.view.refresh();
2083 inputEl: function ()
2085 if(Roo.isIOS && this.useNativeIOS){
2086 return this.el.select('select.roo-ios-select', true).first();
2089 if(Roo.isTouch && this.mobileTouchView){
2090 return this.el.select('input.form-control',true).first();
2094 return this.searchField;
2097 return this.el.select('input.form-control',true).first();
2100 onTickableFooterButtonClick : function(e, btn, el)
2104 this.lastItem = Roo.apply([], this.item);
2106 if(btn && btn.name == 'cancel'){
2107 this.tickItems = Roo.apply([], this.item);
2116 Roo.each(this.tickItems, function(o){
2124 validate : function()
2127 var v = this.getRawValue();
2130 v = this.getValue();
2133 if(this.disabled || this.allowBlank || v.length){
2142 tickableInputEl : function()
2144 if(!this.tickable || !this.editable){
2145 return this.inputEl();
2148 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2152 getAutoCreateTouchView : function()
2157 cls: 'form-group' //input-group
2163 type : this.inputType,
2164 cls : 'form-control x-combo-noedit',
2165 autocomplete: 'new-password',
2166 placeholder : this.placeholder || '',
2171 input.name = this.name;
2175 input.cls += ' input-' + this.size;
2178 if (this.disabled) {
2179 input.disabled = true;
2190 inputblock.cls += ' input-group';
2192 inputblock.cn.unshift({
2194 cls : 'input-group-addon',
2199 if(this.removable && !this.multiple){
2200 inputblock.cls += ' roo-removable';
2202 inputblock.cn.push({
2205 cls : 'roo-combo-removable-btn close'
2209 if(this.hasFeedback && !this.allowBlank){
2211 inputblock.cls += ' has-feedback';
2213 inputblock.cn.push({
2215 cls: 'glyphicon form-control-feedback'
2222 inputblock.cls += (this.before) ? '' : ' input-group';
2224 inputblock.cn.push({
2226 cls : 'input-group-addon',
2237 cls: 'form-hidden-field'
2251 cls: 'form-hidden-field'
2255 cls: 'roo-select2-choices',
2259 cls: 'roo-select2-search-field',
2272 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2278 if(!this.multiple && this.showToggleBtn){
2285 if (this.caret != false) {
2288 cls: 'fa fa-' + this.caret
2295 cls : 'input-group-addon btn dropdown-toggle',
2300 cls: 'combobox-clear',
2314 combobox.cls += ' roo-select2-container-multi';
2317 var align = this.labelAlign || this.parentLabelAlign();
2319 if (align ==='left' && this.fieldLabel.length) {
2324 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2325 tooltip : 'This field is required'
2329 cls : 'control-label',
2330 html : this.fieldLabel
2341 var labelCfg = cfg.cn[1];
2342 var contentCfg = cfg.cn[2];
2345 if(this.indicatorpos == 'right'){
2349 cls : 'control-label',
2350 html : this.fieldLabel
2355 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2356 tooltip : 'This field is required'
2367 labelCfg = cfg.cn[0];
2368 contentCfg = cfg.cn[2];
2370 if(this.labelWidth > 12){
2371 labelCfg.style = "width: " + this.labelWidth + 'px';
2374 if(this.labelWidth < 13 && this.labelmd == 0){
2375 this.labelmd = this.labelWidth;
2378 if(this.labellg > 0){
2379 labelCfg.cls += ' col-lg-' + this.labellg;
2380 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2383 if(this.labelmd > 0){
2384 labelCfg.cls += ' col-md-' + this.labelmd;
2385 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2388 if(this.labelsm > 0){
2389 labelCfg.cls += ' col-sm-' + this.labelsm;
2390 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2393 if(this.labelxs > 0){
2394 labelCfg.cls += ' col-xs-' + this.labelxs;
2395 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2399 } else if ( this.fieldLabel.length) {
2403 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2404 tooltip : 'This field is required'
2408 cls : 'control-label',
2409 html : this.fieldLabel
2420 if(this.indicatorpos == 'right'){
2424 cls : 'control-label',
2425 html : this.fieldLabel
2430 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2431 tooltip : 'This field is required'
2446 var settings = this;
2448 ['xs','sm','md','lg'].map(function(size){
2449 if (settings[size]) {
2450 cfg.cls += ' col-' + size + '-' + settings[size];
2457 initTouchView : function()
2459 this.renderTouchView();
2461 this.touchViewEl.on('scroll', function(){
2462 this.el.dom.scrollTop = 0;
2465 this.originalValue = this.getValue();
2467 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2469 this.inputEl().on("click", this.showTouchView, this);
2470 if (this.triggerEl) {
2471 this.triggerEl.on("click", this.showTouchView, this);
2475 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2476 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2478 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2480 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2481 this.store.on('load', this.onTouchViewLoad, this);
2482 this.store.on('loadexception', this.onTouchViewLoadException, this);
2484 if(this.hiddenName){
2486 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2488 this.hiddenField.dom.value =
2489 this.hiddenValue !== undefined ? this.hiddenValue :
2490 this.value !== undefined ? this.value : '';
2492 this.el.dom.removeAttribute('name');
2493 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2497 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2498 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2501 if(this.removable && !this.multiple){
2502 var close = this.closeTriggerEl();
2504 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2505 close.on('click', this.removeBtnClick, this, close);
2509 * fix the bug in Safari iOS8
2511 this.inputEl().on("focus", function(e){
2512 document.activeElement.blur();
2520 renderTouchView : function()
2522 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2523 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2525 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2526 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2528 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2529 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2530 this.touchViewBodyEl.setStyle('overflow', 'auto');
2532 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2533 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2535 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2536 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2540 showTouchView : function()
2546 this.touchViewHeaderEl.hide();
2548 if(this.modalTitle.length){
2549 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2550 this.touchViewHeaderEl.show();
2553 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2554 this.touchViewEl.show();
2556 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2557 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2558 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2560 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2562 if(this.modalTitle.length){
2563 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2566 this.touchViewBodyEl.setHeight(bodyHeight);
2570 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2572 this.touchViewEl.addClass('in');
2575 this.doTouchViewQuery();
2579 hideTouchView : function()
2581 this.touchViewEl.removeClass('in');
2585 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2587 this.touchViewEl.setStyle('display', 'none');
2592 setTouchViewValue : function()
2599 Roo.each(this.tickItems, function(o){
2604 this.hideTouchView();
2607 doTouchViewQuery : function()
2616 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2620 if(!this.alwaysQuery || this.mode == 'local'){
2621 this.onTouchViewLoad();
2628 onTouchViewBeforeLoad : function(combo,opts)
2634 onTouchViewLoad : function()
2636 if(this.store.getCount() < 1){
2637 this.onTouchViewEmptyResults();
2641 this.clearTouchView();
2643 var rawValue = this.getRawValue();
2645 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2647 this.tickItems = [];
2649 this.store.data.each(function(d, rowIndex){
2650 var row = this.touchViewListGroup.createChild(template);
2652 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2653 row.addClass(d.data.cls);
2656 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2659 html : d.data[this.displayField]
2662 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2663 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2666 row.removeClass('selected');
2667 if(!this.multiple && this.valueField &&
2668 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2671 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2672 row.addClass('selected');
2675 if(this.multiple && this.valueField &&
2676 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2680 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2681 this.tickItems.push(d.data);
2684 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2688 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2690 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2692 if(this.modalTitle.length){
2693 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2696 var listHeight = this.touchViewListGroup.getHeight();
2700 if(firstChecked && listHeight > bodyHeight){
2701 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2706 onTouchViewLoadException : function()
2708 this.hideTouchView();
2711 onTouchViewEmptyResults : function()
2713 this.clearTouchView();
2715 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2717 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2721 clearTouchView : function()
2723 this.touchViewListGroup.dom.innerHTML = '';
2726 onTouchViewClick : function(e, el, o)
2731 var rowIndex = o.rowIndex;
2733 var r = this.store.getAt(rowIndex);
2735 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2738 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2739 c.dom.removeAttribute('checked');
2742 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2744 this.setFromData(r.data);
2746 var close = this.closeTriggerEl();
2752 this.hideTouchView();
2754 this.fireEvent('select', this, r, rowIndex);
2759 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2760 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2761 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2765 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2766 this.addItem(r.data);
2767 this.tickItems.push(r.data);
2771 getAutoCreateNativeIOS : function()
2774 cls: 'form-group' //input-group,
2779 cls : 'roo-ios-select'
2783 combobox.name = this.name;
2786 if (this.disabled) {
2787 combobox.disabled = true;
2790 var settings = this;
2792 ['xs','sm','md','lg'].map(function(size){
2793 if (settings[size]) {
2794 cfg.cls += ' col-' + size + '-' + settings[size];
2804 initIOSView : function()
2806 this.store.on('load', this.onIOSViewLoad, this);
2811 onIOSViewLoad : function()
2813 if(this.store.getCount() < 1){
2817 this.clearIOSView();
2819 if(this.allowBlank) {
2821 var default_text = '-- SELECT --';
2823 var opt = this.inputEl().createChild({
2830 o[this.valueField] = 0;
2831 o[this.displayField] = default_text;
2833 this.ios_options.push({
2840 this.store.data.each(function(d, rowIndex){
2844 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2845 html = d.data[this.displayField];
2850 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2851 value = d.data[this.valueField];
2860 if(this.value == d.data[this.valueField]){
2861 option['selected'] = true;
2864 var opt = this.inputEl().createChild(option);
2866 this.ios_options.push({
2873 this.inputEl().on('change', function(){
2874 this.fireEvent('select', this);
2879 clearIOSView: function()
2881 this.inputEl().dom.innerHTML = '';
2883 this.ios_options = [];
2886 setIOSValue: function(v)
2890 if(!this.ios_options){
2894 Roo.each(this.ios_options, function(opts){
2896 opts.el.dom.removeAttribute('selected');
2898 if(opts.data[this.valueField] != v){
2902 opts.el.dom.setAttribute('selected', true);
2908 * @cfg {Boolean} grow
2912 * @cfg {Number} growMin
2916 * @cfg {Number} growMax
2925 Roo.apply(Roo.bootstrap.ComboBox, {
2929 cls: 'modal-header',
2951 cls: 'list-group-item',
2955 cls: 'roo-combobox-list-group-item-value'
2959 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2973 listItemCheckbox : {
2975 cls: 'list-group-item',
2979 cls: 'roo-combobox-list-group-item-value'
2983 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2999 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3004 cls: 'modal-footer',
3012 cls: 'col-xs-6 text-left',
3015 cls: 'btn btn-danger roo-touch-view-cancel',
3021 cls: 'col-xs-6 text-right',
3024 cls: 'btn btn-success roo-touch-view-ok',
3035 Roo.apply(Roo.bootstrap.ComboBox, {
3037 touchViewTemplate : {
3039 cls: 'modal fade roo-combobox-touch-view',
3043 cls: 'modal-dialog',
3044 style : 'position:fixed', // we have to fix position....
3048 cls: 'modal-content',
3050 Roo.bootstrap.ComboBox.header,
3051 Roo.bootstrap.ComboBox.body,
3052 Roo.bootstrap.ComboBox.footer