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,
323 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
325 mobile_restrict_height : false,
339 btnPosition : 'right',
341 showToggleBtn : true,
343 emptyResultText: 'Empty',
344 triggerText : 'Select',
347 // element that contains real text value.. (when hidden is used..)
349 getAutoCreate : function()
354 * Render classic select for iso
357 if(Roo.isIOS && this.useNativeIOS){
358 cfg = this.getAutoCreateNativeIOS();
366 if(Roo.isTouch && this.mobileTouchView){
367 cfg = this.getAutoCreateTouchView();
375 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
380 * ComboBox with tickable selections
383 var align = this.labelAlign || this.parentLabelAlign();
386 cls : 'form-group roo-combobox-tickable' //input-group
389 var btn_text_select = '';
390 var btn_text_done = '';
391 var btn_text_cancel = '';
393 if (this.btn_text_show) {
394 btn_text_select = 'Select';
395 btn_text_done = 'Done';
396 btn_text_cancel = 'Cancel';
401 cls : 'tickable-buttons',
406 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
407 //html : this.triggerText
408 html: btn_text_select
414 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
422 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
424 html: btn_text_cancel
432 cls: 'roo-select2-search-field-input'
438 Roo.each(buttons.cn, function(c){
440 c.cls += ' btn-' + _this.size;
443 if (_this.disabled) {
454 cls: 'form-hidden-field'
458 cls: 'roo-select2-choices',
462 cls: 'roo-select2-search-field',
473 cls: 'roo-select2-container input-group roo-select2-container-multi',
478 // cls: 'typeahead typeahead-long dropdown-menu',
479 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
484 if(this.hasFeedback && !this.allowBlank){
488 cls: 'glyphicon form-control-feedback'
491 combobox.cn.push(feedback);
496 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
497 tooltip : 'This field is required'
499 if (Roo.bootstrap.version == 4) {
502 style : 'display:none'
505 if (align ==='left' && this.fieldLabel.length) {
507 cfg.cls += ' roo-form-group-label-left row';
514 cls : 'control-label col-form-label',
515 html : this.fieldLabel
527 var labelCfg = cfg.cn[1];
528 var contentCfg = cfg.cn[2];
531 if(this.indicatorpos == 'right'){
537 cls : 'control-label col-form-label',
541 html : this.fieldLabel
557 labelCfg = cfg.cn[0];
558 contentCfg = cfg.cn[1];
562 if(this.labelWidth > 12){
563 labelCfg.style = "width: " + this.labelWidth + 'px';
566 if(this.labelWidth < 13 && this.labelmd == 0){
567 this.labelmd = this.labelWidth;
570 if(this.labellg > 0){
571 labelCfg.cls += ' col-lg-' + this.labellg;
572 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
575 if(this.labelmd > 0){
576 labelCfg.cls += ' col-md-' + this.labelmd;
577 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
580 if(this.labelsm > 0){
581 labelCfg.cls += ' col-sm-' + this.labelsm;
582 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
585 if(this.labelxs > 0){
586 labelCfg.cls += ' col-xs-' + this.labelxs;
587 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
591 } else if ( this.fieldLabel.length) {
592 // Roo.log(" label");
597 //cls : 'input-group-addon',
598 html : this.fieldLabel
603 if(this.indicatorpos == 'right'){
607 //cls : 'input-group-addon',
608 html : this.fieldLabel
618 // Roo.log(" no label && no align");
625 ['xs','sm','md','lg'].map(function(size){
626 if (settings[size]) {
627 cfg.cls += ' col-' + size + '-' + settings[size];
635 _initEventsCalled : false,
638 initEvents: function()
640 if (this._initEventsCalled) { // as we call render... prevent looping...
643 this._initEventsCalled = true;
646 throw "can not find store for combo";
649 this.indicator = this.indicatorEl();
651 this.store = Roo.factory(this.store, Roo.data);
652 this.store.parent = this;
654 // if we are building from html. then this element is so complex, that we can not really
655 // use the rendered HTML.
656 // so we have to trash and replace the previous code.
657 if (Roo.XComponent.build_from_html) {
658 // remove this element....
659 var e = this.el.dom, k=0;
660 while (e ) { e = e.previousSibling; ++k;}
665 this.rendered = false;
667 this.render(this.parent().getChildContainer(true), k);
670 if(Roo.isIOS && this.useNativeIOS){
679 if(Roo.isTouch && this.mobileTouchView){
680 this.initTouchView();
685 this.initTickableEvents();
689 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
693 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
695 this.hiddenField.dom.value =
696 this.hiddenValue !== undefined ? this.hiddenValue :
697 this.value !== undefined ? this.value : '';
699 // prevent input submission
700 this.el.dom.removeAttribute('name');
701 this.hiddenField.dom.setAttribute('name', this.hiddenName);
706 // this.el.dom.setAttribute('autocomplete', 'off');
709 var cls = 'x-combo-list';
711 //this.list = new Roo.Layer({
712 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
718 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
719 _this.list.setWidth(lw);
722 this.list.on('mouseover', this.onViewOver, this);
723 this.list.on('mousemove', this.onViewMove, this);
724 this.list.on('scroll', this.onViewScroll, this);
727 this.list.swallowEvent('mousewheel');
728 this.assetHeight = 0;
731 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
732 this.assetHeight += this.header.getHeight();
735 this.innerList = this.list.createChild({cls:cls+'-inner'});
736 this.innerList.on('mouseover', this.onViewOver, this);
737 this.innerList.on('mousemove', this.onViewMove, this);
738 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
740 if(this.allowBlank && !this.pageSize && !this.disableClear){
741 this.footer = this.list.createChild({cls:cls+'-ft'});
742 this.pageTb = new Roo.Toolbar(this.footer);
746 this.footer = this.list.createChild({cls:cls+'-ft'});
747 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
748 {pageSize: this.pageSize});
752 if (this.pageTb && this.allowBlank && !this.disableClear) {
754 this.pageTb.add(new Roo.Toolbar.Fill(), {
755 cls: 'x-btn-icon x-btn-clear',
761 _this.onSelect(false, -1);
766 this.assetHeight += this.footer.getHeight();
771 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
774 this.view = new Roo.View(this.list, this.tpl, {
775 singleSelect:true, store: this.store, selectedClass: this.selectedClass
777 //this.view.wrapEl.setDisplayed(false);
778 this.view.on('click', this.onViewClick, this);
781 this.store.on('beforeload', this.onBeforeLoad, this);
782 this.store.on('load', this.onLoad, this);
783 this.store.on('loadexception', this.onLoadException, this);
786 this.resizer = new Roo.Resizable(this.list, {
787 pinned:true, handles:'se'
789 this.resizer.on('resize', function(r, w, h){
790 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
792 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
793 this.restrictHeight();
795 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
799 this.editable = true;
800 this.setEditable(false);
805 if (typeof(this.events.add.listeners) != 'undefined') {
807 this.addicon = this.wrap.createChild(
808 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
810 this.addicon.on('click', function(e) {
811 this.fireEvent('add', this);
814 if (typeof(this.events.edit.listeners) != 'undefined') {
816 this.editicon = this.wrap.createChild(
817 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
819 this.editicon.setStyle('margin-left', '40px');
821 this.editicon.on('click', function(e) {
823 // we fire even if inothing is selected..
824 this.fireEvent('edit', this, this.lastData );
830 this.keyNav = new Roo.KeyNav(this.inputEl(), {
832 this.inKeyMode = true;
836 "down" : function(e){
837 if(!this.isExpanded()){
838 this.onTriggerClick();
840 this.inKeyMode = true;
845 "enter" : function(e){
846 // this.onViewClick();
850 if(this.fireEvent("specialkey", this, e)){
851 this.onViewClick(false);
864 if(this.fireEvent("specialkey", this, e)){
865 this.onViewClick(false);
873 doRelay : function(foo, bar, hname){
874 if(hname == 'down' || this.scope.isExpanded()){
875 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
884 this.queryDelay = Math.max(this.queryDelay || 10,
885 this.mode == 'local' ? 10 : 250);
888 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
891 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
893 if(this.editable !== false){
894 this.inputEl().on("keyup", this.onKeyUp, this);
896 if(this.forceSelection){
897 this.inputEl().on('blur', this.doForce, this);
901 this.choices = this.el.select('ul.roo-select2-choices', true).first();
902 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
906 initTickableEvents: function()
912 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
914 this.hiddenField.dom.value =
915 this.hiddenValue !== undefined ? this.hiddenValue :
916 this.value !== undefined ? this.value : '';
918 // prevent input submission
919 this.el.dom.removeAttribute('name');
920 this.hiddenField.dom.setAttribute('name', this.hiddenName);
925 // this.list = this.el.select('ul.dropdown-menu',true).first();
927 this.choices = this.el.select('ul.roo-select2-choices', true).first();
928 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
929 if(this.triggerList){
930 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
933 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
934 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
936 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
937 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
939 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
940 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
942 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
943 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
944 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
947 this.cancelBtn.hide();
952 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
953 _this.list.setWidth(lw);
956 this.list.on('mouseover', this.onViewOver, this);
957 this.list.on('mousemove', this.onViewMove, this);
959 this.list.on('scroll', this.onViewScroll, this);
962 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
963 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
966 this.view = new Roo.View(this.list, this.tpl, {
971 selectedClass: this.selectedClass
974 //this.view.wrapEl.setDisplayed(false);
975 this.view.on('click', this.onViewClick, this);
979 this.store.on('beforeload', this.onBeforeLoad, this);
980 this.store.on('load', this.onLoad, this);
981 this.store.on('loadexception', this.onLoadException, this);
984 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
986 this.inKeyMode = true;
990 "down" : function(e){
991 this.inKeyMode = true;
995 "enter" : function(e){
996 if(this.fireEvent("specialkey", this, e)){
997 this.onViewClick(false);
1003 "esc" : function(e){
1004 this.onTickableFooterButtonClick(e, false, false);
1007 "tab" : function(e){
1008 this.fireEvent("specialkey", this, e);
1010 this.onTickableFooterButtonClick(e, false, false);
1017 doRelay : function(e, fn, key){
1018 if(this.scope.isExpanded()){
1019 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1028 this.queryDelay = Math.max(this.queryDelay || 10,
1029 this.mode == 'local' ? 10 : 250);
1032 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1035 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1038 if(this.editable !== false){
1039 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1042 this.indicator = this.indicatorEl();
1045 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1046 this.indicator.hide();
1051 onDestroy : function(){
1053 this.view.setStore(null);
1054 this.view.el.removeAllListeners();
1055 this.view.el.remove();
1056 this.view.purgeListeners();
1059 this.list.dom.innerHTML = '';
1063 this.store.un('beforeload', this.onBeforeLoad, this);
1064 this.store.un('load', this.onLoad, this);
1065 this.store.un('loadexception', this.onLoadException, this);
1067 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1071 fireKey : function(e){
1072 if(e.isNavKeyPress() && !this.list.isVisible()){
1073 this.fireEvent("specialkey", this, e);
1078 onResize: function(w, h){
1079 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1081 // if(typeof w != 'number'){
1082 // // we do not handle it!?!?
1085 // var tw = this.trigger.getWidth();
1086 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1087 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1089 // this.inputEl().setWidth( this.adjustWidth('input', x));
1091 // //this.trigger.setStyle('left', x+'px');
1093 // if(this.list && this.listWidth === undefined){
1094 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1095 // this.list.setWidth(lw);
1096 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1104 * Allow or prevent the user from directly editing the field text. If false is passed,
1105 * the user will only be able to select from the items defined in the dropdown list. This method
1106 * is the runtime equivalent of setting the 'editable' config option at config time.
1107 * @param {Boolean} value True to allow the user to directly edit the field text
1109 setEditable : function(value){
1110 if(value == this.editable){
1113 this.editable = value;
1115 this.inputEl().dom.setAttribute('readOnly', true);
1116 this.inputEl().on('mousedown', this.onTriggerClick, this);
1117 this.inputEl().addClass('x-combo-noedit');
1119 this.inputEl().dom.setAttribute('readOnly', false);
1120 this.inputEl().un('mousedown', this.onTriggerClick, this);
1121 this.inputEl().removeClass('x-combo-noedit');
1127 onBeforeLoad : function(combo,opts){
1132 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1134 this.restrictHeight();
1135 this.selectedIndex = -1;
1139 onLoad : function(){
1141 this.hasQuery = false;
1147 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1148 this.loading.hide();
1151 if(this.store.getCount() > 0){
1154 this.restrictHeight();
1155 if(this.lastQuery == this.allQuery){
1156 if(this.editable && !this.tickable){
1157 this.inputEl().dom.select();
1161 !this.selectByValue(this.value, true) &&
1164 !this.store.lastOptions ||
1165 typeof(this.store.lastOptions.add) == 'undefined' ||
1166 this.store.lastOptions.add != true
1169 this.select(0, true);
1175 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1176 this.taTask.delay(this.typeAheadDelay);
1180 this.onEmptyResults();
1186 onLoadException : function()
1188 this.hasQuery = false;
1190 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1191 this.loading.hide();
1194 if(this.tickable && this.editable){
1199 // only causes errors at present
1200 //Roo.log(this.store.reader.jsonData);
1201 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1203 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1209 onTypeAhead : function(){
1210 if(this.store.getCount() > 0){
1211 var r = this.store.getAt(0);
1212 var newValue = r.data[this.displayField];
1213 var len = newValue.length;
1214 var selStart = this.getRawValue().length;
1216 if(selStart != len){
1217 this.setRawValue(newValue);
1218 this.selectText(selStart, newValue.length);
1224 onSelect : function(record, index){
1226 if(this.fireEvent('beforeselect', this, record, index) !== false){
1228 this.setFromData(index > -1 ? record.data : false);
1231 this.fireEvent('select', this, record, index);
1236 * Returns the currently selected field value or empty string if no value is set.
1237 * @return {String} value The selected value
1239 getValue : function()
1241 if(Roo.isIOS && this.useNativeIOS){
1242 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1246 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1249 if(this.valueField){
1250 return typeof this.value != 'undefined' ? this.value : '';
1252 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1256 getRawValue : function()
1258 if(Roo.isIOS && this.useNativeIOS){
1259 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1262 var v = this.inputEl().getValue();
1268 * Clears any text/value currently set in the field
1270 clearValue : function(){
1272 if(this.hiddenField){
1273 this.hiddenField.dom.value = '';
1276 this.setRawValue('');
1277 this.lastSelectionText = '';
1278 this.lastData = false;
1280 var close = this.closeTriggerEl();
1291 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1292 * will be displayed in the field. If the value does not match the data value of an existing item,
1293 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1294 * Otherwise the field will be blank (although the value will still be set).
1295 * @param {String} value The value to match
1297 setValue : function(v)
1299 if(Roo.isIOS && this.useNativeIOS){
1300 this.setIOSValue(v);
1310 if(this.valueField){
1311 var r = this.findRecord(this.valueField, v);
1313 text = r.data[this.displayField];
1314 }else if(this.valueNotFoundText !== undefined){
1315 text = this.valueNotFoundText;
1318 this.lastSelectionText = text;
1319 if(this.hiddenField){
1320 this.hiddenField.dom.value = v;
1322 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1325 var close = this.closeTriggerEl();
1328 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1334 * @property {Object} the last set data for the element
1339 * Sets the value of the field based on a object which is related to the record format for the store.
1340 * @param {Object} value the value to set as. or false on reset?
1342 setFromData : function(o){
1349 var dv = ''; // display value
1350 var vv = ''; // value value..
1352 if (this.displayField) {
1353 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1355 // this is an error condition!!!
1356 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1359 if(this.valueField){
1360 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1363 var close = this.closeTriggerEl();
1366 if(dv.length || vv * 1 > 0){
1368 this.blockFocus=true;
1374 if(this.hiddenField){
1375 this.hiddenField.dom.value = vv;
1377 this.lastSelectionText = dv;
1378 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1382 // no hidden field.. - we store the value in 'value', but still display
1383 // display field!!!!
1384 this.lastSelectionText = dv;
1385 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1393 // overridden so that last data is reset..
1400 this.setValue(this.originalValue);
1401 //this.clearInvalid();
1402 this.lastData = false;
1404 this.view.clearSelections();
1410 findRecord : function(prop, value){
1412 if(this.store.getCount() > 0){
1413 this.store.each(function(r){
1414 if(r.data[prop] == value){
1426 // returns hidden if it's set..
1427 if (!this.rendered) {return ''};
1428 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1432 onViewMove : function(e, t){
1433 this.inKeyMode = false;
1437 onViewOver : function(e, t){
1438 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1441 var item = this.view.findItemFromChild(t);
1444 var index = this.view.indexOf(item);
1445 this.select(index, false);
1450 onViewClick : function(view, doFocus, el, e)
1452 var index = this.view.getSelectedIndexes()[0];
1454 var r = this.store.getAt(index);
1458 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1465 Roo.each(this.tickItems, function(v,k){
1467 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1469 _this.tickItems.splice(k, 1);
1471 if(typeof(e) == 'undefined' && view == false){
1472 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1484 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1485 this.tickItems.push(r.data);
1488 if(typeof(e) == 'undefined' && view == false){
1489 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1496 this.onSelect(r, index);
1498 if(doFocus !== false && !this.blockFocus){
1499 this.inputEl().focus();
1504 restrictHeight : function(){
1505 //this.innerList.dom.style.height = '';
1506 //var inner = this.innerList.dom;
1507 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1508 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1509 //this.list.beginUpdate();
1510 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1511 this.list.alignTo(this.inputEl(), this.listAlign);
1512 this.list.alignTo(this.inputEl(), this.listAlign);
1513 //this.list.endUpdate();
1517 onEmptyResults : function(){
1519 if(this.tickable && this.editable){
1520 this.hasFocus = false;
1521 this.restrictHeight();
1529 * Returns true if the dropdown list is expanded, else false.
1531 isExpanded : function(){
1532 return this.list.isVisible();
1536 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1537 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1538 * @param {String} value The data value of the item to select
1539 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1540 * selected item if it is not currently in view (defaults to true)
1541 * @return {Boolean} True if the value matched an item in the list, else false
1543 selectByValue : function(v, scrollIntoView){
1544 if(v !== undefined && v !== null){
1545 var r = this.findRecord(this.valueField || this.displayField, v);
1547 this.select(this.store.indexOf(r), scrollIntoView);
1555 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1556 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1557 * @param {Number} index The zero-based index of the list item to select
1558 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1559 * selected item if it is not currently in view (defaults to true)
1561 select : function(index, scrollIntoView){
1562 this.selectedIndex = index;
1563 this.view.select(index);
1564 if(scrollIntoView !== false){
1565 var el = this.view.getNode(index);
1567 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1570 this.list.scrollChildIntoView(el, false);
1576 selectNext : function(){
1577 var ct = this.store.getCount();
1579 if(this.selectedIndex == -1){
1581 }else if(this.selectedIndex < ct-1){
1582 this.select(this.selectedIndex+1);
1588 selectPrev : function(){
1589 var ct = this.store.getCount();
1591 if(this.selectedIndex == -1){
1593 }else if(this.selectedIndex != 0){
1594 this.select(this.selectedIndex-1);
1600 onKeyUp : function(e){
1601 if(this.editable !== false && !e.isSpecialKey()){
1602 this.lastKey = e.getKey();
1603 this.dqTask.delay(this.queryDelay);
1608 validateBlur : function(){
1609 return !this.list || !this.list.isVisible();
1613 initQuery : function(){
1615 var v = this.getRawValue();
1617 if(this.tickable && this.editable){
1618 v = this.tickableInputEl().getValue();
1625 doForce : function(){
1626 if(this.inputEl().dom.value.length > 0){
1627 this.inputEl().dom.value =
1628 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1634 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1635 * query allowing the query action to be canceled if needed.
1636 * @param {String} query The SQL query to execute
1637 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1638 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1639 * saved in the current store (defaults to false)
1641 doQuery : function(q, forceAll){
1643 if(q === undefined || q === null){
1652 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1657 forceAll = qe.forceAll;
1658 if(forceAll === true || (q.length >= this.minChars)){
1660 this.hasQuery = true;
1662 if(this.lastQuery != q || this.alwaysQuery){
1664 if(this.mode == 'local'){
1665 this.selectedIndex = -1;
1667 this.store.clearFilter();
1670 if(this.specialFilter){
1671 this.fireEvent('specialfilter', this);
1676 this.store.filter(this.displayField, q);
1679 this.store.fireEvent("datachanged", this.store);
1686 this.store.baseParams[this.queryParam] = q;
1688 var options = {params : this.getParams(q)};
1692 options.params.start = this.page * this.pageSize;
1695 this.store.load(options);
1698 * this code will make the page width larger, at the beginning, the list not align correctly,
1699 * we should expand the list on onLoad
1705 this.selectedIndex = -1;
1710 this.loadNext = false;
1714 getParams : function(q){
1716 //p[this.queryParam] = q;
1720 p.limit = this.pageSize;
1726 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1728 collapse : function(){
1729 if(!this.isExpanded()){
1735 this.hasFocus = false;
1739 this.cancelBtn.hide();
1740 this.trigger.show();
1743 this.tickableInputEl().dom.value = '';
1744 this.tickableInputEl().blur();
1749 Roo.get(document).un('mousedown', this.collapseIf, this);
1750 Roo.get(document).un('mousewheel', this.collapseIf, this);
1751 if (!this.editable) {
1752 Roo.get(document).un('keydown', this.listKeyPress, this);
1754 this.fireEvent('collapse', this);
1760 collapseIf : function(e){
1761 var in_combo = e.within(this.el);
1762 var in_list = e.within(this.list);
1763 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1765 if (in_combo || in_list || is_list) {
1766 //e.stopPropagation();
1771 this.onTickableFooterButtonClick(e, false, false);
1779 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1781 expand : function(){
1783 if(this.isExpanded() || !this.hasFocus){
1787 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1788 this.list.setWidth(lw);
1794 this.restrictHeight();
1798 this.tickItems = Roo.apply([], this.item);
1801 this.cancelBtn.show();
1802 this.trigger.hide();
1805 this.tickableInputEl().focus();
1810 Roo.get(document).on('mousedown', this.collapseIf, this);
1811 Roo.get(document).on('mousewheel', this.collapseIf, this);
1812 if (!this.editable) {
1813 Roo.get(document).on('keydown', this.listKeyPress, this);
1816 this.fireEvent('expand', this);
1820 // Implements the default empty TriggerField.onTriggerClick function
1821 onTriggerClick : function(e)
1823 Roo.log('trigger click');
1825 if(this.disabled || !this.triggerList){
1830 this.loadNext = false;
1832 if(this.isExpanded()){
1834 if (!this.blockFocus) {
1835 this.inputEl().focus();
1839 this.hasFocus = true;
1840 if(this.triggerAction == 'all') {
1841 this.doQuery(this.allQuery, true);
1843 this.doQuery(this.getRawValue());
1845 if (!this.blockFocus) {
1846 this.inputEl().focus();
1851 onTickableTriggerClick : function(e)
1858 this.loadNext = false;
1859 this.hasFocus = true;
1861 if(this.triggerAction == 'all') {
1862 this.doQuery(this.allQuery, true);
1864 this.doQuery(this.getRawValue());
1868 onSearchFieldClick : function(e)
1870 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1871 this.onTickableFooterButtonClick(e, false, false);
1875 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1880 this.loadNext = false;
1881 this.hasFocus = true;
1883 if(this.triggerAction == 'all') {
1884 this.doQuery(this.allQuery, true);
1886 this.doQuery(this.getRawValue());
1890 listKeyPress : function(e)
1892 //Roo.log('listkeypress');
1893 // scroll to first matching element based on key pres..
1894 if (e.isSpecialKey()) {
1897 var k = String.fromCharCode(e.getKey()).toUpperCase();
1900 var csel = this.view.getSelectedNodes();
1901 var cselitem = false;
1903 var ix = this.view.indexOf(csel[0]);
1904 cselitem = this.store.getAt(ix);
1905 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1911 this.store.each(function(v) {
1913 // start at existing selection.
1914 if (cselitem.id == v.id) {
1920 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1921 match = this.store.indexOf(v);
1927 if (match === false) {
1928 return true; // no more action?
1931 this.view.select(match);
1932 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1933 sn.scrollIntoView(sn.dom.parentNode, false);
1936 onViewScroll : function(e, t){
1938 if(this.view.el.getScroll().top == 0 ||this.view.el.getScroll().top < this.view.el.dom.scrollHeight - this.view.el.dom.clientHeight || !this.hasFocus || !this.append || this.hasQuery){
1942 this.hasQuery = true;
1944 this.loading = this.list.select('.loading', true).first();
1946 if(this.loading === null){
1947 this.list.createChild({
1949 cls: 'loading roo-select2-more-results roo-select2-active',
1950 html: 'Loading more results...'
1953 this.loading = this.list.select('.loading', true).first();
1955 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1957 this.loading.hide();
1960 this.loading.show();
1965 this.loadNext = true;
1967 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1972 addItem : function(o)
1974 var dv = ''; // display value
1976 if (this.displayField) {
1977 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1979 // this is an error condition!!!
1980 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1987 var choice = this.choices.createChild({
1989 cls: 'roo-select2-search-choice',
1998 cls: 'roo-select2-search-choice-close fa fa-times',
2003 }, this.searchField);
2005 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2007 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2015 this.inputEl().dom.value = '';
2020 onRemoveItem : function(e, _self, o)
2024 this.lastItem = Roo.apply([], this.item);
2026 var index = this.item.indexOf(o.data) * 1;
2029 Roo.log('not this item?!');
2033 this.item.splice(index, 1);
2038 this.fireEvent('remove', this, e);
2044 syncValue : function()
2046 if(!this.item.length){
2053 Roo.each(this.item, function(i){
2054 if(_this.valueField){
2055 value.push(i[_this.valueField]);
2062 this.value = value.join(',');
2064 if(this.hiddenField){
2065 this.hiddenField.dom.value = this.value;
2068 this.store.fireEvent("datachanged", this.store);
2073 clearItem : function()
2081 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2089 if(this.tickable && !Roo.isTouch){
2090 this.view.refresh();
2094 inputEl: function ()
2096 if(Roo.isIOS && this.useNativeIOS){
2097 return this.el.select('select.roo-ios-select', true).first();
2100 if(Roo.isTouch && this.mobileTouchView){
2101 return this.el.select('input.form-control',true).first();
2105 return this.searchField;
2108 return this.el.select('input.form-control',true).first();
2111 onTickableFooterButtonClick : function(e, btn, el)
2115 this.lastItem = Roo.apply([], this.item);
2117 if(btn && btn.name == 'cancel'){
2118 this.tickItems = Roo.apply([], this.item);
2127 Roo.each(this.tickItems, function(o){
2135 validate : function()
2137 if(this.getVisibilityEl().hasClass('hidden')){
2141 var v = this.getRawValue();
2144 v = this.getValue();
2147 if(this.disabled || this.allowBlank || v.length){
2156 tickableInputEl : function()
2158 if(!this.tickable || !this.editable){
2159 return this.inputEl();
2162 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2166 getAutoCreateTouchView : function()
2171 cls: 'form-group' //input-group
2177 type : this.inputType,
2178 cls : 'form-control x-combo-noedit',
2179 autocomplete: 'new-password',
2180 placeholder : this.placeholder || '',
2185 input.name = this.name;
2189 input.cls += ' input-' + this.size;
2192 if (this.disabled) {
2193 input.disabled = true;
2204 inputblock.cls += ' input-group';
2206 inputblock.cn.unshift({
2208 cls : 'input-group-addon input-group-prepend input-group-text',
2213 if(this.removable && !this.multiple){
2214 inputblock.cls += ' roo-removable';
2216 inputblock.cn.push({
2219 cls : 'roo-combo-removable-btn close'
2223 if(this.hasFeedback && !this.allowBlank){
2225 inputblock.cls += ' has-feedback';
2227 inputblock.cn.push({
2229 cls: 'glyphicon form-control-feedback'
2236 inputblock.cls += (this.before) ? '' : ' input-group';
2238 inputblock.cn.push({
2240 cls : 'input-group-addon input-group-append input-group-text',
2251 cls: 'form-hidden-field'
2265 cls: 'form-hidden-field'
2269 cls: 'roo-select2-choices',
2273 cls: 'roo-select2-search-field',
2286 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2292 if(!this.multiple && this.showToggleBtn){
2299 if (this.caret != false) {
2302 cls: 'fa fa-' + this.caret
2309 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2314 cls: 'combobox-clear',
2328 combobox.cls += ' roo-select2-container-multi';
2331 var align = this.labelAlign || this.parentLabelAlign();
2333 if (align ==='left' && this.fieldLabel.length) {
2338 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2339 tooltip : 'This field is required'
2343 cls : 'control-label col-form-label',
2344 html : this.fieldLabel
2355 var labelCfg = cfg.cn[1];
2356 var contentCfg = cfg.cn[2];
2359 if(this.indicatorpos == 'right'){
2364 cls : 'control-label col-form-label',
2368 html : this.fieldLabel
2372 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2373 tooltip : 'This field is required'
2386 labelCfg = cfg.cn[0];
2387 contentCfg = cfg.cn[1];
2392 if(this.labelWidth > 12){
2393 labelCfg.style = "width: " + this.labelWidth + 'px';
2396 if(this.labelWidth < 13 && this.labelmd == 0){
2397 this.labelmd = this.labelWidth;
2400 if(this.labellg > 0){
2401 labelCfg.cls += ' col-lg-' + this.labellg;
2402 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2405 if(this.labelmd > 0){
2406 labelCfg.cls += ' col-md-' + this.labelmd;
2407 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2410 if(this.labelsm > 0){
2411 labelCfg.cls += ' col-sm-' + this.labelsm;
2412 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2415 if(this.labelxs > 0){
2416 labelCfg.cls += ' col-xs-' + this.labelxs;
2417 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2421 } else if ( this.fieldLabel.length) {
2425 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2426 tooltip : 'This field is required'
2430 cls : 'control-label',
2431 html : this.fieldLabel
2442 if(this.indicatorpos == 'right'){
2446 cls : 'control-label',
2447 html : this.fieldLabel,
2451 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2452 tooltip : 'This field is required'
2469 var settings = this;
2471 ['xs','sm','md','lg'].map(function(size){
2472 if (settings[size]) {
2473 cfg.cls += ' col-' + size + '-' + settings[size];
2480 initTouchView : function()
2482 this.renderTouchView();
2484 this.touchViewEl.on('scroll', function(){
2485 this.el.dom.scrollTop = 0;
2488 this.originalValue = this.getValue();
2490 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2492 this.inputEl().on("click", this.showTouchView, this);
2493 if (this.triggerEl) {
2494 this.triggerEl.on("click", this.showTouchView, this);
2498 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2499 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2501 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2503 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2504 this.store.on('load', this.onTouchViewLoad, this);
2505 this.store.on('loadexception', this.onTouchViewLoadException, this);
2507 if(this.hiddenName){
2509 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2511 this.hiddenField.dom.value =
2512 this.hiddenValue !== undefined ? this.hiddenValue :
2513 this.value !== undefined ? this.value : '';
2515 this.el.dom.removeAttribute('name');
2516 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2520 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2521 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2524 if(this.removable && !this.multiple){
2525 var close = this.closeTriggerEl();
2527 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2528 close.on('click', this.removeBtnClick, this, close);
2532 * fix the bug in Safari iOS8
2534 this.inputEl().on("focus", function(e){
2535 document.activeElement.blur();
2538 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2545 renderTouchView : function()
2547 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2548 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2550 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2551 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2553 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2554 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2555 this.touchViewBodyEl.setStyle('overflow', 'auto');
2557 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2558 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2560 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2561 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2565 showTouchView : function()
2571 this.touchViewHeaderEl.hide();
2573 if(this.modalTitle.length){
2574 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2575 this.touchViewHeaderEl.show();
2578 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2579 this.touchViewEl.show();
2581 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2583 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2584 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2586 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2588 if(this.modalTitle.length){
2589 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2592 this.touchViewBodyEl.setHeight(bodyHeight);
2596 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2598 this.touchViewEl.addClass('in');
2601 if(this._touchViewMask){
2602 Roo.get(document.body).addClass("x-body-masked");
2603 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2604 this._touchViewMask.setStyle('z-index', 10000);
2605 this._touchViewMask.addClass('show');
2608 this.doTouchViewQuery();
2612 hideTouchView : function()
2614 this.touchViewEl.removeClass('in');
2618 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2620 this.touchViewEl.setStyle('display', 'none');
2623 if(this._touchViewMask){
2624 this._touchViewMask.removeClass('show');
2625 Roo.get(document.body).removeClass("x-body-masked");
2629 setTouchViewValue : function()
2636 Roo.each(this.tickItems, function(o){
2641 this.hideTouchView();
2644 doTouchViewQuery : function()
2653 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2657 if(!this.alwaysQuery || this.mode == 'local'){
2658 this.onTouchViewLoad();
2665 onTouchViewBeforeLoad : function(combo,opts)
2671 onTouchViewLoad : function()
2673 if(this.store.getCount() < 1){
2674 this.onTouchViewEmptyResults();
2678 this.clearTouchView();
2680 var rawValue = this.getRawValue();
2682 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2684 this.tickItems = [];
2686 this.store.data.each(function(d, rowIndex){
2687 var row = this.touchViewListGroup.createChild(template);
2689 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2690 row.addClass(d.data.cls);
2693 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2696 html : d.data[this.displayField]
2699 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2700 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2703 row.removeClass('selected');
2704 if(!this.multiple && this.valueField &&
2705 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2708 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2709 row.addClass('selected');
2712 if(this.multiple && this.valueField &&
2713 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2717 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2718 this.tickItems.push(d.data);
2721 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2725 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2727 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2729 if(this.modalTitle.length){
2730 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2733 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2735 if(this.mobile_restrict_height && listHeight < bodyHeight){
2736 this.touchViewBodyEl.setHeight(listHeight);
2741 if(firstChecked && listHeight > bodyHeight){
2742 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2747 onTouchViewLoadException : function()
2749 this.hideTouchView();
2752 onTouchViewEmptyResults : function()
2754 this.clearTouchView();
2756 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2758 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2762 clearTouchView : function()
2764 this.touchViewListGroup.dom.innerHTML = '';
2767 onTouchViewClick : function(e, el, o)
2772 var rowIndex = o.rowIndex;
2774 var r = this.store.getAt(rowIndex);
2776 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2779 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2780 c.dom.removeAttribute('checked');
2783 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2785 this.setFromData(r.data);
2787 var close = this.closeTriggerEl();
2793 this.hideTouchView();
2795 this.fireEvent('select', this, r, rowIndex);
2800 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2801 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2802 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2806 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2807 this.addItem(r.data);
2808 this.tickItems.push(r.data);
2812 getAutoCreateNativeIOS : function()
2815 cls: 'form-group' //input-group,
2820 cls : 'roo-ios-select'
2824 combobox.name = this.name;
2827 if (this.disabled) {
2828 combobox.disabled = true;
2831 var settings = this;
2833 ['xs','sm','md','lg'].map(function(size){
2834 if (settings[size]) {
2835 cfg.cls += ' col-' + size + '-' + settings[size];
2845 initIOSView : function()
2847 this.store.on('load', this.onIOSViewLoad, this);
2852 onIOSViewLoad : function()
2854 if(this.store.getCount() < 1){
2858 this.clearIOSView();
2860 if(this.allowBlank) {
2862 var default_text = '-- SELECT --';
2864 if(this.placeholder.length){
2865 default_text = this.placeholder;
2868 if(this.emptyTitle.length){
2869 default_text += ' - ' + this.emptyTitle + ' -';
2872 var opt = this.inputEl().createChild({
2879 o[this.valueField] = 0;
2880 o[this.displayField] = default_text;
2882 this.ios_options.push({
2889 this.store.data.each(function(d, rowIndex){
2893 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2894 html = d.data[this.displayField];
2899 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2900 value = d.data[this.valueField];
2909 if(this.value == d.data[this.valueField]){
2910 option['selected'] = true;
2913 var opt = this.inputEl().createChild(option);
2915 this.ios_options.push({
2922 this.inputEl().on('change', function(){
2923 this.fireEvent('select', this);
2928 clearIOSView: function()
2930 this.inputEl().dom.innerHTML = '';
2932 this.ios_options = [];
2935 setIOSValue: function(v)
2939 if(!this.ios_options){
2943 Roo.each(this.ios_options, function(opts){
2945 opts.el.dom.removeAttribute('selected');
2947 if(opts.data[this.valueField] != v){
2951 opts.el.dom.setAttribute('selected', true);
2957 * @cfg {Boolean} grow
2961 * @cfg {Number} growMin
2965 * @cfg {Number} growMax
2974 Roo.apply(Roo.bootstrap.ComboBox, {
2978 cls: 'modal-header',
3000 cls: 'list-group-item',
3004 cls: 'roo-combobox-list-group-item-value'
3008 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3022 listItemCheckbox : {
3024 cls: 'list-group-item',
3028 cls: 'roo-combobox-list-group-item-value'
3032 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3048 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3053 cls: 'modal-footer',
3061 cls: 'col-xs-6 text-left',
3064 cls: 'btn btn-danger roo-touch-view-cancel',
3070 cls: 'col-xs-6 text-right',
3073 cls: 'btn btn-success roo-touch-view-ok',
3084 Roo.apply(Roo.bootstrap.ComboBox, {
3086 touchViewTemplate : {
3088 cls: 'modal fade roo-combobox-touch-view',
3092 cls: 'modal-dialog',
3093 style : 'position:fixed', // we have to fix position....
3097 cls: 'modal-content',
3099 Roo.bootstrap.ComboBox.header,
3100 Roo.bootstrap.ComboBox.body,
3101 Roo.bootstrap.ComboBox.footer