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',
479 // cls: 'typeahead typeahead-long dropdown-menu',
480 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
485 if(this.hasFeedback && !this.allowBlank){
489 cls: 'glyphicon form-control-feedback'
492 combobox.cn.push(feedback);
497 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
498 tooltip : 'This field is required'
500 if (Roo.bootstrap.version == 4) {
503 style : 'display:none'
506 if (align ==='left' && this.fieldLabel.length) {
508 cfg.cls += ' roo-form-group-label-left row';
515 cls : 'control-label col-form-label',
516 html : this.fieldLabel
528 var labelCfg = cfg.cn[1];
529 var contentCfg = cfg.cn[2];
532 if(this.indicatorpos == 'right'){
538 cls : 'control-label col-form-label',
542 html : this.fieldLabel
558 labelCfg = cfg.cn[0];
559 contentCfg = cfg.cn[1];
563 if(this.labelWidth > 12){
564 labelCfg.style = "width: " + this.labelWidth + 'px';
567 if(this.labelWidth < 13 && this.labelmd == 0){
568 this.labelmd = this.labelWidth;
571 if(this.labellg > 0){
572 labelCfg.cls += ' col-lg-' + this.labellg;
573 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
576 if(this.labelmd > 0){
577 labelCfg.cls += ' col-md-' + this.labelmd;
578 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
581 if(this.labelsm > 0){
582 labelCfg.cls += ' col-sm-' + this.labelsm;
583 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
586 if(this.labelxs > 0){
587 labelCfg.cls += ' col-xs-' + this.labelxs;
588 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
592 } else if ( this.fieldLabel.length) {
593 // Roo.log(" label");
598 //cls : 'input-group-addon',
599 html : this.fieldLabel
604 if(this.indicatorpos == 'right'){
608 //cls : 'input-group-addon',
609 html : this.fieldLabel
619 // Roo.log(" no label && no align");
626 ['xs','sm','md','lg'].map(function(size){
627 if (settings[size]) {
628 cfg.cls += ' col-' + size + '-' + settings[size];
636 _initEventsCalled : false,
639 initEvents: function()
641 if (this._initEventsCalled) { // as we call render... prevent looping...
644 this._initEventsCalled = true;
647 throw "can not find store for combo";
650 this.indicator = this.indicatorEl();
652 this.store = Roo.factory(this.store, Roo.data);
653 this.store.parent = this;
655 // if we are building from html. then this element is so complex, that we can not really
656 // use the rendered HTML.
657 // so we have to trash and replace the previous code.
658 if (Roo.XComponent.build_from_html) {
659 // remove this element....
660 var e = this.el.dom, k=0;
661 while (e ) { e = e.previousSibling; ++k;}
666 this.rendered = false;
668 this.render(this.parent().getChildContainer(true), k);
671 if(Roo.isIOS && this.useNativeIOS){
680 if(Roo.isTouch && this.mobileTouchView){
681 this.initTouchView();
686 this.initTickableEvents();
690 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
694 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
696 this.hiddenField.dom.value =
697 this.hiddenValue !== undefined ? this.hiddenValue :
698 this.value !== undefined ? this.value : '';
700 // prevent input submission
701 this.el.dom.removeAttribute('name');
702 this.hiddenField.dom.setAttribute('name', this.hiddenName);
707 // this.el.dom.setAttribute('autocomplete', 'off');
710 var cls = 'x-combo-list';
712 //this.list = new Roo.Layer({
713 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
719 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
720 _this.list.setWidth(lw);
723 this.list.on('mouseover', this.onViewOver, this);
724 this.list.on('mousemove', this.onViewMove, this);
725 this.list.on('scroll', this.onViewScroll, this);
728 this.list.swallowEvent('mousewheel');
729 this.assetHeight = 0;
732 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
733 this.assetHeight += this.header.getHeight();
736 this.innerList = this.list.createChild({cls:cls+'-inner'});
737 this.innerList.on('mouseover', this.onViewOver, this);
738 this.innerList.on('mousemove', this.onViewMove, this);
739 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
741 if(this.allowBlank && !this.pageSize && !this.disableClear){
742 this.footer = this.list.createChild({cls:cls+'-ft'});
743 this.pageTb = new Roo.Toolbar(this.footer);
747 this.footer = this.list.createChild({cls:cls+'-ft'});
748 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
749 {pageSize: this.pageSize});
753 if (this.pageTb && this.allowBlank && !this.disableClear) {
755 this.pageTb.add(new Roo.Toolbar.Fill(), {
756 cls: 'x-btn-icon x-btn-clear',
762 _this.onSelect(false, -1);
767 this.assetHeight += this.footer.getHeight();
772 this.tpl = Roo.bootstrap.version == 4 ?
773 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
774 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
777 this.view = new Roo.View(this.list, this.tpl, {
778 singleSelect:true, store: this.store, selectedClass: this.selectedClass
780 //this.view.wrapEl.setDisplayed(false);
781 this.view.on('click', this.onViewClick, this);
784 this.store.on('beforeload', this.onBeforeLoad, this);
785 this.store.on('load', this.onLoad, this);
786 this.store.on('loadexception', this.onLoadException, this);
789 this.resizer = new Roo.Resizable(this.list, {
790 pinned:true, handles:'se'
792 this.resizer.on('resize', function(r, w, h){
793 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
795 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
796 this.restrictHeight();
798 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
802 this.editable = true;
803 this.setEditable(false);
808 if (typeof(this.events.add.listeners) != 'undefined') {
810 this.addicon = this.wrap.createChild(
811 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
813 this.addicon.on('click', function(e) {
814 this.fireEvent('add', this);
817 if (typeof(this.events.edit.listeners) != 'undefined') {
819 this.editicon = this.wrap.createChild(
820 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
822 this.editicon.setStyle('margin-left', '40px');
824 this.editicon.on('click', function(e) {
826 // we fire even if inothing is selected..
827 this.fireEvent('edit', this, this.lastData );
833 this.keyNav = new Roo.KeyNav(this.inputEl(), {
835 this.inKeyMode = true;
839 "down" : function(e){
840 if(!this.isExpanded()){
841 this.onTriggerClick();
843 this.inKeyMode = true;
848 "enter" : function(e){
849 // this.onViewClick();
853 if(this.fireEvent("specialkey", this, e)){
854 this.onViewClick(false);
867 if(this.fireEvent("specialkey", this, e)){
868 this.onViewClick(false);
876 doRelay : function(foo, bar, hname){
877 if(hname == 'down' || this.scope.isExpanded()){
878 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
887 this.queryDelay = Math.max(this.queryDelay || 10,
888 this.mode == 'local' ? 10 : 250);
891 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
894 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
896 if(this.editable !== false){
897 this.inputEl().on("keyup", this.onKeyUp, this);
899 if(this.forceSelection){
900 this.inputEl().on('blur', this.doForce, this);
904 this.choices = this.el.select('ul.roo-select2-choices', true).first();
905 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
909 initTickableEvents: function()
915 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
917 this.hiddenField.dom.value =
918 this.hiddenValue !== undefined ? this.hiddenValue :
919 this.value !== undefined ? this.value : '';
921 // prevent input submission
922 this.el.dom.removeAttribute('name');
923 this.hiddenField.dom.setAttribute('name', this.hiddenName);
928 // this.list = this.el.select('ul.dropdown-menu',true).first();
930 this.choices = this.el.select('ul.roo-select2-choices', true).first();
931 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
932 if(this.triggerList){
933 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
936 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
937 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
939 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
940 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
942 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
943 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
945 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
946 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
947 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
950 this.cancelBtn.hide();
955 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
956 _this.list.setWidth(lw);
959 this.list.on('mouseover', this.onViewOver, this);
960 this.list.on('mousemove', this.onViewMove, this);
962 this.list.on('scroll', this.onViewScroll, this);
965 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
966 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
969 this.view = new Roo.View(this.list, this.tpl, {
974 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);
1045 this.indicator = this.indicatorEl();
1048 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1049 this.indicator.hide();
1054 onDestroy : function(){
1056 this.view.setStore(null);
1057 this.view.el.removeAllListeners();
1058 this.view.el.remove();
1059 this.view.purgeListeners();
1062 this.list.dom.innerHTML = '';
1066 this.store.un('beforeload', this.onBeforeLoad, this);
1067 this.store.un('load', this.onLoad, this);
1068 this.store.un('loadexception', this.onLoadException, this);
1070 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1074 fireKey : function(e){
1075 if(e.isNavKeyPress() && !this.list.isVisible()){
1076 this.fireEvent("specialkey", this, e);
1081 onResize: function(w, h){
1082 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1084 // if(typeof w != 'number'){
1085 // // we do not handle it!?!?
1088 // var tw = this.trigger.getWidth();
1089 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1090 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1092 // this.inputEl().setWidth( this.adjustWidth('input', x));
1094 // //this.trigger.setStyle('left', x+'px');
1096 // if(this.list && this.listWidth === undefined){
1097 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1098 // this.list.setWidth(lw);
1099 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1107 * Allow or prevent the user from directly editing the field text. If false is passed,
1108 * the user will only be able to select from the items defined in the dropdown list. This method
1109 * is the runtime equivalent of setting the 'editable' config option at config time.
1110 * @param {Boolean} value True to allow the user to directly edit the field text
1112 setEditable : function(value){
1113 if(value == this.editable){
1116 this.editable = value;
1118 this.inputEl().dom.setAttribute('readOnly', true);
1119 this.inputEl().on('mousedown', this.onTriggerClick, this);
1120 this.inputEl().addClass('x-combo-noedit');
1122 this.inputEl().dom.setAttribute('readOnly', false);
1123 this.inputEl().un('mousedown', this.onTriggerClick, this);
1124 this.inputEl().removeClass('x-combo-noedit');
1130 onBeforeLoad : function(combo,opts){
1135 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1137 this.restrictHeight();
1138 this.selectedIndex = -1;
1142 onLoad : function(){
1144 this.hasQuery = false;
1150 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1151 this.loading.hide();
1154 if(this.store.getCount() > 0){
1157 this.restrictHeight();
1158 if(this.lastQuery == this.allQuery){
1159 if(this.editable && !this.tickable){
1160 this.inputEl().dom.select();
1164 !this.selectByValue(this.value, true) &&
1167 !this.store.lastOptions ||
1168 typeof(this.store.lastOptions.add) == 'undefined' ||
1169 this.store.lastOptions.add != true
1172 this.select(0, true);
1178 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1179 this.taTask.delay(this.typeAheadDelay);
1183 this.onEmptyResults();
1189 onLoadException : function()
1191 this.hasQuery = false;
1193 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1194 this.loading.hide();
1197 if(this.tickable && this.editable){
1202 // only causes errors at present
1203 //Roo.log(this.store.reader.jsonData);
1204 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1206 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1212 onTypeAhead : function(){
1213 if(this.store.getCount() > 0){
1214 var r = this.store.getAt(0);
1215 var newValue = r.data[this.displayField];
1216 var len = newValue.length;
1217 var selStart = this.getRawValue().length;
1219 if(selStart != len){
1220 this.setRawValue(newValue);
1221 this.selectText(selStart, newValue.length);
1227 onSelect : function(record, index){
1229 if(this.fireEvent('beforeselect', this, record, index) !== false){
1231 this.setFromData(index > -1 ? record.data : false);
1234 this.fireEvent('select', this, record, index);
1239 * Returns the currently selected field value or empty string if no value is set.
1240 * @return {String} value The selected value
1242 getValue : function()
1244 if(Roo.isIOS && this.useNativeIOS){
1245 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1249 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1252 if(this.valueField){
1253 return typeof this.value != 'undefined' ? this.value : '';
1255 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1259 getRawValue : function()
1261 if(Roo.isIOS && this.useNativeIOS){
1262 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1265 var v = this.inputEl().getValue();
1271 * Clears any text/value currently set in the field
1273 clearValue : function(){
1275 if(this.hiddenField){
1276 this.hiddenField.dom.value = '';
1279 this.setRawValue('');
1280 this.lastSelectionText = '';
1281 this.lastData = false;
1283 var close = this.closeTriggerEl();
1294 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1295 * will be displayed in the field. If the value does not match the data value of an existing item,
1296 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1297 * Otherwise the field will be blank (although the value will still be set).
1298 * @param {String} value The value to match
1300 setValue : function(v)
1302 if(Roo.isIOS && this.useNativeIOS){
1303 this.setIOSValue(v);
1313 if(this.valueField){
1314 var r = this.findRecord(this.valueField, v);
1316 text = r.data[this.displayField];
1317 }else if(this.valueNotFoundText !== undefined){
1318 text = this.valueNotFoundText;
1321 this.lastSelectionText = text;
1322 if(this.hiddenField){
1323 this.hiddenField.dom.value = v;
1325 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1328 var close = this.closeTriggerEl();
1331 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1337 * @property {Object} the last set data for the element
1342 * Sets the value of the field based on a object which is related to the record format for the store.
1343 * @param {Object} value the value to set as. or false on reset?
1345 setFromData : function(o){
1352 var dv = ''; // display value
1353 var vv = ''; // value value..
1355 if (this.displayField) {
1356 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1358 // this is an error condition!!!
1359 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1362 if(this.valueField){
1363 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1366 var close = this.closeTriggerEl();
1369 if(dv.length || vv * 1 > 0){
1371 this.blockFocus=true;
1377 if(this.hiddenField){
1378 this.hiddenField.dom.value = vv;
1380 this.lastSelectionText = dv;
1381 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1385 // no hidden field.. - we store the value in 'value', but still display
1386 // display field!!!!
1387 this.lastSelectionText = dv;
1388 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1396 // overridden so that last data is reset..
1403 this.setValue(this.originalValue);
1404 //this.clearInvalid();
1405 this.lastData = false;
1407 this.view.clearSelections();
1413 findRecord : function(prop, value){
1415 if(this.store.getCount() > 0){
1416 this.store.each(function(r){
1417 if(r.data[prop] == value){
1429 // returns hidden if it's set..
1430 if (!this.rendered) {return ''};
1431 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1435 onViewMove : function(e, t){
1436 this.inKeyMode = false;
1440 onViewOver : function(e, t){
1441 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1444 var item = this.view.findItemFromChild(t);
1447 var index = this.view.indexOf(item);
1448 this.select(index, false);
1453 onViewClick : function(view, doFocus, el, e)
1455 var index = this.view.getSelectedIndexes()[0];
1457 var r = this.store.getAt(index);
1461 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1468 Roo.each(this.tickItems, function(v,k){
1470 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1472 _this.tickItems.splice(k, 1);
1474 if(typeof(e) == 'undefined' && view == false){
1475 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1487 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1488 this.tickItems.push(r.data);
1491 if(typeof(e) == 'undefined' && view == false){
1492 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1499 this.onSelect(r, index);
1501 if(doFocus !== false && !this.blockFocus){
1502 this.inputEl().focus();
1507 restrictHeight : function(){
1508 //this.innerList.dom.style.height = '';
1509 //var inner = this.innerList.dom;
1510 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1511 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1512 //this.list.beginUpdate();
1513 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1514 this.list.alignTo(this.inputEl(), this.listAlign);
1515 this.list.alignTo(this.inputEl(), this.listAlign);
1516 //this.list.endUpdate();
1520 onEmptyResults : function(){
1522 if(this.tickable && this.editable){
1523 this.hasFocus = false;
1524 this.restrictHeight();
1532 * Returns true if the dropdown list is expanded, else false.
1534 isExpanded : function(){
1535 return this.list.isVisible();
1539 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1540 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1541 * @param {String} value The data value of the item to select
1542 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1543 * selected item if it is not currently in view (defaults to true)
1544 * @return {Boolean} True if the value matched an item in the list, else false
1546 selectByValue : function(v, scrollIntoView){
1547 if(v !== undefined && v !== null){
1548 var r = this.findRecord(this.valueField || this.displayField, v);
1550 this.select(this.store.indexOf(r), scrollIntoView);
1558 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1559 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1560 * @param {Number} index The zero-based index of the list item to select
1561 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1562 * selected item if it is not currently in view (defaults to true)
1564 select : function(index, scrollIntoView){
1565 this.selectedIndex = index;
1566 this.view.select(index);
1567 if(scrollIntoView !== false){
1568 var el = this.view.getNode(index);
1570 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1573 this.list.scrollChildIntoView(el, false);
1579 selectNext : function(){
1580 var ct = this.store.getCount();
1582 if(this.selectedIndex == -1){
1584 }else if(this.selectedIndex < ct-1){
1585 this.select(this.selectedIndex+1);
1591 selectPrev : function(){
1592 var ct = this.store.getCount();
1594 if(this.selectedIndex == -1){
1596 }else if(this.selectedIndex != 0){
1597 this.select(this.selectedIndex-1);
1603 onKeyUp : function(e){
1604 if(this.editable !== false && !e.isSpecialKey()){
1605 this.lastKey = e.getKey();
1606 this.dqTask.delay(this.queryDelay);
1611 validateBlur : function(){
1612 return !this.list || !this.list.isVisible();
1616 initQuery : function(){
1618 var v = this.getRawValue();
1620 if(this.tickable && this.editable){
1621 v = this.tickableInputEl().getValue();
1628 doForce : function(){
1629 if(this.inputEl().dom.value.length > 0){
1630 this.inputEl().dom.value =
1631 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1637 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1638 * query allowing the query action to be canceled if needed.
1639 * @param {String} query The SQL query to execute
1640 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1641 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1642 * saved in the current store (defaults to false)
1644 doQuery : function(q, forceAll){
1646 if(q === undefined || q === null){
1655 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1660 forceAll = qe.forceAll;
1661 if(forceAll === true || (q.length >= this.minChars)){
1663 this.hasQuery = true;
1665 if(this.lastQuery != q || this.alwaysQuery){
1667 if(this.mode == 'local'){
1668 this.selectedIndex = -1;
1670 this.store.clearFilter();
1673 if(this.specialFilter){
1674 this.fireEvent('specialfilter', this);
1679 this.store.filter(this.displayField, q);
1682 this.store.fireEvent("datachanged", this.store);
1689 this.store.baseParams[this.queryParam] = q;
1691 var options = {params : this.getParams(q)};
1695 options.params.start = this.page * this.pageSize;
1698 this.store.load(options);
1701 * this code will make the page width larger, at the beginning, the list not align correctly,
1702 * we should expand the list on onLoad
1708 this.selectedIndex = -1;
1713 this.loadNext = false;
1717 getParams : function(q){
1719 //p[this.queryParam] = q;
1723 p.limit = this.pageSize;
1729 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1731 collapse : function(){
1732 if(!this.isExpanded()){
1738 this.hasFocus = false;
1742 this.cancelBtn.hide();
1743 this.trigger.show();
1746 this.tickableInputEl().dom.value = '';
1747 this.tickableInputEl().blur();
1752 Roo.get(document).un('mousedown', this.collapseIf, this);
1753 Roo.get(document).un('mousewheel', this.collapseIf, this);
1754 if (!this.editable) {
1755 Roo.get(document).un('keydown', this.listKeyPress, this);
1757 this.fireEvent('collapse', this);
1763 collapseIf : function(e){
1764 var in_combo = e.within(this.el);
1765 var in_list = e.within(this.list);
1766 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1768 if (in_combo || in_list || is_list) {
1769 //e.stopPropagation();
1774 this.onTickableFooterButtonClick(e, false, false);
1782 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1784 expand : function(){
1786 if(this.isExpanded() || !this.hasFocus){
1790 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1791 this.list.setWidth(lw);
1797 this.restrictHeight();
1801 this.tickItems = Roo.apply([], this.item);
1804 this.cancelBtn.show();
1805 this.trigger.hide();
1808 this.tickableInputEl().focus();
1813 Roo.get(document).on('mousedown', this.collapseIf, this);
1814 Roo.get(document).on('mousewheel', this.collapseIf, this);
1815 if (!this.editable) {
1816 Roo.get(document).on('keydown', this.listKeyPress, this);
1819 this.fireEvent('expand', this);
1823 // Implements the default empty TriggerField.onTriggerClick function
1824 onTriggerClick : function(e)
1826 Roo.log('trigger click');
1828 if(this.disabled || !this.triggerList){
1833 this.loadNext = false;
1835 if(this.isExpanded()){
1837 if (!this.blockFocus) {
1838 this.inputEl().focus();
1842 this.hasFocus = true;
1843 if(this.triggerAction == 'all') {
1844 this.doQuery(this.allQuery, true);
1846 this.doQuery(this.getRawValue());
1848 if (!this.blockFocus) {
1849 this.inputEl().focus();
1854 onTickableTriggerClick : function(e)
1861 this.loadNext = false;
1862 this.hasFocus = true;
1864 if(this.triggerAction == 'all') {
1865 this.doQuery(this.allQuery, true);
1867 this.doQuery(this.getRawValue());
1871 onSearchFieldClick : function(e)
1873 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1874 this.onTickableFooterButtonClick(e, false, false);
1878 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1883 this.loadNext = false;
1884 this.hasFocus = true;
1886 if(this.triggerAction == 'all') {
1887 this.doQuery(this.allQuery, true);
1889 this.doQuery(this.getRawValue());
1893 listKeyPress : function(e)
1895 //Roo.log('listkeypress');
1896 // scroll to first matching element based on key pres..
1897 if (e.isSpecialKey()) {
1900 var k = String.fromCharCode(e.getKey()).toUpperCase();
1903 var csel = this.view.getSelectedNodes();
1904 var cselitem = false;
1906 var ix = this.view.indexOf(csel[0]);
1907 cselitem = this.store.getAt(ix);
1908 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1914 this.store.each(function(v) {
1916 // start at existing selection.
1917 if (cselitem.id == v.id) {
1923 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1924 match = this.store.indexOf(v);
1930 if (match === false) {
1931 return true; // no more action?
1934 this.view.select(match);
1935 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1936 sn.scrollIntoView(sn.dom.parentNode, false);
1939 onViewScroll : function(e, t){
1941 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){
1945 this.hasQuery = true;
1947 this.loading = this.list.select('.loading', true).first();
1949 if(this.loading === null){
1950 this.list.createChild({
1952 cls: 'loading roo-select2-more-results roo-select2-active',
1953 html: 'Loading more results...'
1956 this.loading = this.list.select('.loading', true).first();
1958 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1960 this.loading.hide();
1963 this.loading.show();
1968 this.loadNext = true;
1970 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1975 addItem : function(o)
1977 var dv = ''; // display value
1979 if (this.displayField) {
1980 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1982 // this is an error condition!!!
1983 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1990 var choice = this.choices.createChild({
1992 cls: 'roo-select2-search-choice',
2001 cls: 'roo-select2-search-choice-close fa fa-times',
2006 }, this.searchField);
2008 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2010 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2018 this.inputEl().dom.value = '';
2023 onRemoveItem : function(e, _self, o)
2027 this.lastItem = Roo.apply([], this.item);
2029 var index = this.item.indexOf(o.data) * 1;
2032 Roo.log('not this item?!');
2036 this.item.splice(index, 1);
2041 this.fireEvent('remove', this, e);
2047 syncValue : function()
2049 if(!this.item.length){
2056 Roo.each(this.item, function(i){
2057 if(_this.valueField){
2058 value.push(i[_this.valueField]);
2065 this.value = value.join(',');
2067 if(this.hiddenField){
2068 this.hiddenField.dom.value = this.value;
2071 this.store.fireEvent("datachanged", this.store);
2076 clearItem : function()
2084 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2092 if(this.tickable && !Roo.isTouch){
2093 this.view.refresh();
2097 inputEl: function ()
2099 if(Roo.isIOS && this.useNativeIOS){
2100 return this.el.select('select.roo-ios-select', true).first();
2103 if(Roo.isTouch && this.mobileTouchView){
2104 return this.el.select('input.form-control',true).first();
2108 return this.searchField;
2111 return this.el.select('input.form-control',true).first();
2114 onTickableFooterButtonClick : function(e, btn, el)
2118 this.lastItem = Roo.apply([], this.item);
2120 if(btn && btn.name == 'cancel'){
2121 this.tickItems = Roo.apply([], this.item);
2130 Roo.each(this.tickItems, function(o){
2138 validate : function()
2140 if(this.getVisibilityEl().hasClass('hidden')){
2144 var v = this.getRawValue();
2147 v = this.getValue();
2150 if(this.disabled || this.allowBlank || v.length){
2159 tickableInputEl : function()
2161 if(!this.tickable || !this.editable){
2162 return this.inputEl();
2165 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2169 getAutoCreateTouchView : function()
2174 cls: 'form-group' //input-group
2180 type : this.inputType,
2181 cls : 'form-control x-combo-noedit',
2182 autocomplete: 'new-password',
2183 placeholder : this.placeholder || '',
2188 input.name = this.name;
2192 input.cls += ' input-' + this.size;
2195 if (this.disabled) {
2196 input.disabled = true;
2207 inputblock.cls += ' input-group';
2209 inputblock.cn.unshift({
2211 cls : 'input-group-addon input-group-prepend input-group-text',
2216 if(this.removable && !this.multiple){
2217 inputblock.cls += ' roo-removable';
2219 inputblock.cn.push({
2222 cls : 'roo-combo-removable-btn close'
2226 if(this.hasFeedback && !this.allowBlank){
2228 inputblock.cls += ' has-feedback';
2230 inputblock.cn.push({
2232 cls: 'glyphicon form-control-feedback'
2239 inputblock.cls += (this.before) ? '' : ' input-group';
2241 inputblock.cn.push({
2243 cls : 'input-group-addon input-group-append input-group-text',
2249 var ibwrap = inputblock;
2254 cls: 'roo-select2-choices',
2258 cls: 'roo-select2-search-field',
2271 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2276 cls: 'form-hidden-field'
2282 if(!this.multiple && this.showToggleBtn){
2289 if (this.caret != false) {
2292 cls: 'fa fa-' + this.caret
2299 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2304 cls: 'combobox-clear',
2318 combobox.cls += ' roo-select2-container-multi';
2321 var align = this.labelAlign || this.parentLabelAlign();
2323 if (align ==='left' && this.fieldLabel.length) {
2328 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2329 tooltip : 'This field is required'
2333 cls : 'control-label col-form-label',
2334 html : this.fieldLabel
2345 var labelCfg = cfg.cn[1];
2346 var contentCfg = cfg.cn[2];
2349 if(this.indicatorpos == 'right'){
2354 cls : 'control-label col-form-label',
2358 html : this.fieldLabel
2362 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2363 tooltip : 'This field is required'
2376 labelCfg = cfg.cn[0];
2377 contentCfg = cfg.cn[1];
2382 if(this.labelWidth > 12){
2383 labelCfg.style = "width: " + this.labelWidth + 'px';
2386 if(this.labelWidth < 13 && this.labelmd == 0){
2387 this.labelmd = this.labelWidth;
2390 if(this.labellg > 0){
2391 labelCfg.cls += ' col-lg-' + this.labellg;
2392 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2395 if(this.labelmd > 0){
2396 labelCfg.cls += ' col-md-' + this.labelmd;
2397 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2400 if(this.labelsm > 0){
2401 labelCfg.cls += ' col-sm-' + this.labelsm;
2402 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2405 if(this.labelxs > 0){
2406 labelCfg.cls += ' col-xs-' + this.labelxs;
2407 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2411 } else if ( this.fieldLabel.length) {
2415 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2416 tooltip : 'This field is required'
2420 cls : 'control-label',
2421 html : this.fieldLabel
2432 if(this.indicatorpos == 'right'){
2436 cls : 'control-label',
2437 html : this.fieldLabel,
2441 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2442 tooltip : 'This field is required'
2459 var settings = this;
2461 ['xs','sm','md','lg'].map(function(size){
2462 if (settings[size]) {
2463 cfg.cls += ' col-' + size + '-' + settings[size];
2470 initTouchView : function()
2472 this.renderTouchView();
2474 this.touchViewEl.on('scroll', function(){
2475 this.el.dom.scrollTop = 0;
2478 this.originalValue = this.getValue();
2480 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2482 this.inputEl().on("click", this.showTouchView, this);
2483 if (this.triggerEl) {
2484 this.triggerEl.on("click", this.showTouchView, this);
2488 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2489 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2491 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2493 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2494 this.store.on('load', this.onTouchViewLoad, this);
2495 this.store.on('loadexception', this.onTouchViewLoadException, this);
2497 if(this.hiddenName){
2499 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2501 this.hiddenField.dom.value =
2502 this.hiddenValue !== undefined ? this.hiddenValue :
2503 this.value !== undefined ? this.value : '';
2505 this.el.dom.removeAttribute('name');
2506 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2510 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2511 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2514 if(this.removable && !this.multiple){
2515 var close = this.closeTriggerEl();
2517 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2518 close.on('click', this.removeBtnClick, this, close);
2522 * fix the bug in Safari iOS8
2524 this.inputEl().on("focus", function(e){
2525 document.activeElement.blur();
2528 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2535 renderTouchView : function()
2537 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2538 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2540 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2541 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2543 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2544 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2545 this.touchViewBodyEl.setStyle('overflow', 'auto');
2547 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2548 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2550 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2551 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2555 showTouchView : function()
2561 this.touchViewHeaderEl.hide();
2563 if(this.modalTitle.length){
2564 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2565 this.touchViewHeaderEl.show();
2568 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2569 this.touchViewEl.show();
2571 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2573 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2574 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2576 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2578 if(this.modalTitle.length){
2579 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2582 this.touchViewBodyEl.setHeight(bodyHeight);
2586 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2588 this.touchViewEl.addClass('in');
2591 if(this._touchViewMask){
2592 Roo.get(document.body).addClass("x-body-masked");
2593 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2594 this._touchViewMask.setStyle('z-index', 10000);
2595 this._touchViewMask.addClass('show');
2598 this.doTouchViewQuery();
2602 hideTouchView : function()
2604 this.touchViewEl.removeClass('in');
2608 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2610 this.touchViewEl.setStyle('display', 'none');
2613 if(this._touchViewMask){
2614 this._touchViewMask.removeClass('show');
2615 Roo.get(document.body).removeClass("x-body-masked");
2619 setTouchViewValue : function()
2626 Roo.each(this.tickItems, function(o){
2631 this.hideTouchView();
2634 doTouchViewQuery : function()
2643 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2647 if(!this.alwaysQuery || this.mode == 'local'){
2648 this.onTouchViewLoad();
2655 onTouchViewBeforeLoad : function(combo,opts)
2661 onTouchViewLoad : function()
2663 if(this.store.getCount() < 1){
2664 this.onTouchViewEmptyResults();
2668 this.clearTouchView();
2670 var rawValue = this.getRawValue();
2672 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2674 this.tickItems = [];
2676 this.store.data.each(function(d, rowIndex){
2677 var row = this.touchViewListGroup.createChild(template);
2679 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2680 row.addClass(d.data.cls);
2683 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2686 html : d.data[this.displayField]
2689 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2690 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2693 row.removeClass('selected');
2694 if(!this.multiple && this.valueField &&
2695 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2698 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2699 row.addClass('selected');
2702 if(this.multiple && this.valueField &&
2703 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2707 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2708 this.tickItems.push(d.data);
2711 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2715 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2717 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2719 if(this.modalTitle.length){
2720 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2723 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2725 if(this.mobile_restrict_height && listHeight < bodyHeight){
2726 this.touchViewBodyEl.setHeight(listHeight);
2731 if(firstChecked && listHeight > bodyHeight){
2732 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2737 onTouchViewLoadException : function()
2739 this.hideTouchView();
2742 onTouchViewEmptyResults : function()
2744 this.clearTouchView();
2746 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2748 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2752 clearTouchView : function()
2754 this.touchViewListGroup.dom.innerHTML = '';
2757 onTouchViewClick : function(e, el, o)
2762 var rowIndex = o.rowIndex;
2764 var r = this.store.getAt(rowIndex);
2766 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2769 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2770 c.dom.removeAttribute('checked');
2773 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2775 this.setFromData(r.data);
2777 var close = this.closeTriggerEl();
2783 this.hideTouchView();
2785 this.fireEvent('select', this, r, rowIndex);
2790 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2791 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2792 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2796 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2797 this.addItem(r.data);
2798 this.tickItems.push(r.data);
2802 getAutoCreateNativeIOS : function()
2805 cls: 'form-group' //input-group,
2810 cls : 'roo-ios-select'
2814 combobox.name = this.name;
2817 if (this.disabled) {
2818 combobox.disabled = true;
2821 var settings = this;
2823 ['xs','sm','md','lg'].map(function(size){
2824 if (settings[size]) {
2825 cfg.cls += ' col-' + size + '-' + settings[size];
2835 initIOSView : function()
2837 this.store.on('load', this.onIOSViewLoad, this);
2842 onIOSViewLoad : function()
2844 if(this.store.getCount() < 1){
2848 this.clearIOSView();
2850 if(this.allowBlank) {
2852 var default_text = '-- SELECT --';
2854 if(this.placeholder.length){
2855 default_text = this.placeholder;
2858 if(this.emptyTitle.length){
2859 default_text += ' - ' + this.emptyTitle + ' -';
2862 var opt = this.inputEl().createChild({
2869 o[this.valueField] = 0;
2870 o[this.displayField] = default_text;
2872 this.ios_options.push({
2879 this.store.data.each(function(d, rowIndex){
2883 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2884 html = d.data[this.displayField];
2889 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2890 value = d.data[this.valueField];
2899 if(this.value == d.data[this.valueField]){
2900 option['selected'] = true;
2903 var opt = this.inputEl().createChild(option);
2905 this.ios_options.push({
2912 this.inputEl().on('change', function(){
2913 this.fireEvent('select', this);
2918 clearIOSView: function()
2920 this.inputEl().dom.innerHTML = '';
2922 this.ios_options = [];
2925 setIOSValue: function(v)
2929 if(!this.ios_options){
2933 Roo.each(this.ios_options, function(opts){
2935 opts.el.dom.removeAttribute('selected');
2937 if(opts.data[this.valueField] != v){
2941 opts.el.dom.setAttribute('selected', true);
2947 * @cfg {Boolean} grow
2951 * @cfg {Number} growMin
2955 * @cfg {Number} growMax
2964 Roo.apply(Roo.bootstrap.ComboBox, {
2968 cls: 'modal-header',
2990 cls: 'list-group-item',
2994 cls: 'roo-combobox-list-group-item-value'
2998 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3012 listItemCheckbox : {
3014 cls: 'list-group-item',
3018 cls: 'roo-combobox-list-group-item-value'
3022 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3038 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3043 cls: 'modal-footer',
3051 cls: 'col-xs-6 text-left',
3054 cls: 'btn btn-danger roo-touch-view-cancel',
3060 cls: 'col-xs-6 text-right',
3063 cls: 'btn btn-success roo-touch-view-ok',
3074 Roo.apply(Roo.bootstrap.ComboBox, {
3076 touchViewTemplate : {
3078 cls: 'modal fade roo-combobox-touch-view',
3082 cls: 'modal-dialog',
3083 style : 'position:fixed', // we have to fix position....
3087 cls: 'modal-content',
3089 Roo.bootstrap.ComboBox.header,
3090 Roo.bootstrap.ComboBox.body,
3091 Roo.bootstrap.ComboBox.footer