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);
495 if (align ==='left' && this.fieldLabel.length) {
497 cfg.cls += ' roo-form-group-label-left';
502 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
503 tooltip : 'This field is required'
508 cls : 'control-label',
509 html : this.fieldLabel
521 var labelCfg = cfg.cn[1];
522 var contentCfg = cfg.cn[2];
525 if(this.indicatorpos == 'right'){
531 cls : 'control-label',
535 html : this.fieldLabel
539 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
540 tooltip : 'This field is required'
555 labelCfg = cfg.cn[0];
556 contentCfg = cfg.cn[1];
560 if(this.labelWidth > 12){
561 labelCfg.style = "width: " + this.labelWidth + 'px';
564 if(this.labelWidth < 13 && this.labelmd == 0){
565 this.labelmd = this.labelWidth;
568 if(this.labellg > 0){
569 labelCfg.cls += ' col-lg-' + this.labellg;
570 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
573 if(this.labelmd > 0){
574 labelCfg.cls += ' col-md-' + this.labelmd;
575 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
578 if(this.labelsm > 0){
579 labelCfg.cls += ' col-sm-' + this.labelsm;
580 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
583 if(this.labelxs > 0){
584 labelCfg.cls += ' col-xs-' + this.labelxs;
585 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
589 } else if ( this.fieldLabel.length) {
590 // Roo.log(" label");
594 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
595 tooltip : 'This field is required'
599 //cls : 'input-group-addon',
600 html : this.fieldLabel
605 if(this.indicatorpos == 'right'){
609 //cls : 'input-group-addon',
610 html : this.fieldLabel
614 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
615 tooltip : 'This field is required'
624 // Roo.log(" no label && no align");
631 ['xs','sm','md','lg'].map(function(size){
632 if (settings[size]) {
633 cfg.cls += ' col-' + size + '-' + settings[size];
641 _initEventsCalled : false,
644 initEvents: function()
646 if (this._initEventsCalled) { // as we call render... prevent looping...
649 this._initEventsCalled = true;
652 throw "can not find store for combo";
655 this.indicator = this.indicatorEl();
657 this.store = Roo.factory(this.store, Roo.data);
658 this.store.parent = this;
660 // if we are building from html. then this element is so complex, that we can not really
661 // use the rendered HTML.
662 // so we have to trash and replace the previous code.
663 if (Roo.XComponent.build_from_html) {
664 // remove this element....
665 var e = this.el.dom, k=0;
666 while (e ) { e = e.previousSibling; ++k;}
671 this.rendered = false;
673 this.render(this.parent().getChildContainer(true), k);
676 if(Roo.isIOS && this.useNativeIOS){
685 if(Roo.isTouch && this.mobileTouchView){
686 this.initTouchView();
691 this.initTickableEvents();
695 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
699 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
701 this.hiddenField.dom.value =
702 this.hiddenValue !== undefined ? this.hiddenValue :
703 this.value !== undefined ? this.value : '';
705 // prevent input submission
706 this.el.dom.removeAttribute('name');
707 this.hiddenField.dom.setAttribute('name', this.hiddenName);
712 // this.el.dom.setAttribute('autocomplete', 'off');
715 var cls = 'x-combo-list';
717 //this.list = new Roo.Layer({
718 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
724 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
725 _this.list.setWidth(lw);
728 this.list.on('mouseover', this.onViewOver, this);
729 this.list.on('mousemove', this.onViewMove, this);
730 this.list.on('scroll', this.onViewScroll, this);
733 this.list.swallowEvent('mousewheel');
734 this.assetHeight = 0;
737 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
738 this.assetHeight += this.header.getHeight();
741 this.innerList = this.list.createChild({cls:cls+'-inner'});
742 this.innerList.on('mouseover', this.onViewOver, this);
743 this.innerList.on('mousemove', this.onViewMove, this);
744 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
746 if(this.allowBlank && !this.pageSize && !this.disableClear){
747 this.footer = this.list.createChild({cls:cls+'-ft'});
748 this.pageTb = new Roo.Toolbar(this.footer);
752 this.footer = this.list.createChild({cls:cls+'-ft'});
753 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
754 {pageSize: this.pageSize});
758 if (this.pageTb && this.allowBlank && !this.disableClear) {
760 this.pageTb.add(new Roo.Toolbar.Fill(), {
761 cls: 'x-btn-icon x-btn-clear',
767 _this.onSelect(false, -1);
772 this.assetHeight += this.footer.getHeight();
777 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
780 this.view = new Roo.View(this.list, this.tpl, {
781 singleSelect:true, store: this.store, selectedClass: this.selectedClass
783 //this.view.wrapEl.setDisplayed(false);
784 this.view.on('click', this.onViewClick, this);
787 this.store.on('beforeload', this.onBeforeLoad, this);
788 this.store.on('load', this.onLoad, this);
789 this.store.on('loadexception', this.onLoadException, this);
792 this.resizer = new Roo.Resizable(this.list, {
793 pinned:true, handles:'se'
795 this.resizer.on('resize', function(r, w, h){
796 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
798 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
799 this.restrictHeight();
801 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
805 this.editable = true;
806 this.setEditable(false);
811 if (typeof(this.events.add.listeners) != 'undefined') {
813 this.addicon = this.wrap.createChild(
814 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
816 this.addicon.on('click', function(e) {
817 this.fireEvent('add', this);
820 if (typeof(this.events.edit.listeners) != 'undefined') {
822 this.editicon = this.wrap.createChild(
823 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
825 this.editicon.setStyle('margin-left', '40px');
827 this.editicon.on('click', function(e) {
829 // we fire even if inothing is selected..
830 this.fireEvent('edit', this, this.lastData );
836 this.keyNav = new Roo.KeyNav(this.inputEl(), {
838 this.inKeyMode = true;
842 "down" : function(e){
843 if(!this.isExpanded()){
844 this.onTriggerClick();
846 this.inKeyMode = true;
851 "enter" : function(e){
852 // this.onViewClick();
856 if(this.fireEvent("specialkey", this, e)){
857 this.onViewClick(false);
870 if(this.fireEvent("specialkey", this, e)){
871 this.onViewClick(false);
879 doRelay : function(foo, bar, hname){
880 if(hname == 'down' || this.scope.isExpanded()){
881 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
890 this.queryDelay = Math.max(this.queryDelay || 10,
891 this.mode == 'local' ? 10 : 250);
894 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
897 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
899 if(this.editable !== false){
900 this.inputEl().on("keyup", this.onKeyUp, this);
902 if(this.forceSelection){
903 this.inputEl().on('blur', this.doForce, this);
907 this.choices = this.el.select('ul.roo-select2-choices', true).first();
908 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
912 initTickableEvents: function()
918 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
920 this.hiddenField.dom.value =
921 this.hiddenValue !== undefined ? this.hiddenValue :
922 this.value !== undefined ? this.value : '';
924 // prevent input submission
925 this.el.dom.removeAttribute('name');
926 this.hiddenField.dom.setAttribute('name', this.hiddenName);
931 // this.list = this.el.select('ul.dropdown-menu',true).first();
933 this.choices = this.el.select('ul.roo-select2-choices', true).first();
934 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
935 if(this.triggerList){
936 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
939 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
940 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
942 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
943 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
945 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
946 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
948 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
949 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
950 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
953 this.cancelBtn.hide();
958 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
959 _this.list.setWidth(lw);
962 this.list.on('mouseover', this.onViewOver, this);
963 this.list.on('mousemove', this.onViewMove, this);
965 this.list.on('scroll', this.onViewScroll, this);
968 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
969 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
972 this.view = new Roo.View(this.list, this.tpl, {
977 selectedClass: this.selectedClass
980 //this.view.wrapEl.setDisplayed(false);
981 this.view.on('click', this.onViewClick, this);
985 this.store.on('beforeload', this.onBeforeLoad, this);
986 this.store.on('load', this.onLoad, this);
987 this.store.on('loadexception', this.onLoadException, this);
990 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
992 this.inKeyMode = true;
996 "down" : function(e){
997 this.inKeyMode = true;
1001 "enter" : function(e){
1002 if(this.fireEvent("specialkey", this, e)){
1003 this.onViewClick(false);
1009 "esc" : function(e){
1010 this.onTickableFooterButtonClick(e, false, false);
1013 "tab" : function(e){
1014 this.fireEvent("specialkey", this, e);
1016 this.onTickableFooterButtonClick(e, false, false);
1023 doRelay : function(e, fn, key){
1024 if(this.scope.isExpanded()){
1025 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1034 this.queryDelay = Math.max(this.queryDelay || 10,
1035 this.mode == 'local' ? 10 : 250);
1038 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1041 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1044 if(this.editable !== false){
1045 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1048 this.indicator = this.indicatorEl();
1051 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1052 this.indicator.hide();
1057 onDestroy : function(){
1059 this.view.setStore(null);
1060 this.view.el.removeAllListeners();
1061 this.view.el.remove();
1062 this.view.purgeListeners();
1065 this.list.dom.innerHTML = '';
1069 this.store.un('beforeload', this.onBeforeLoad, this);
1070 this.store.un('load', this.onLoad, this);
1071 this.store.un('loadexception', this.onLoadException, this);
1073 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1077 fireKey : function(e){
1078 if(e.isNavKeyPress() && !this.list.isVisible()){
1079 this.fireEvent("specialkey", this, e);
1084 onResize: function(w, h){
1085 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1087 // if(typeof w != 'number'){
1088 // // we do not handle it!?!?
1091 // var tw = this.trigger.getWidth();
1092 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1093 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1095 // this.inputEl().setWidth( this.adjustWidth('input', x));
1097 // //this.trigger.setStyle('left', x+'px');
1099 // if(this.list && this.listWidth === undefined){
1100 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1101 // this.list.setWidth(lw);
1102 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1110 * Allow or prevent the user from directly editing the field text. If false is passed,
1111 * the user will only be able to select from the items defined in the dropdown list. This method
1112 * is the runtime equivalent of setting the 'editable' config option at config time.
1113 * @param {Boolean} value True to allow the user to directly edit the field text
1115 setEditable : function(value){
1116 if(value == this.editable){
1119 this.editable = value;
1121 this.inputEl().dom.setAttribute('readOnly', true);
1122 this.inputEl().on('mousedown', this.onTriggerClick, this);
1123 this.inputEl().addClass('x-combo-noedit');
1125 this.inputEl().dom.setAttribute('readOnly', false);
1126 this.inputEl().un('mousedown', this.onTriggerClick, this);
1127 this.inputEl().removeClass('x-combo-noedit');
1133 onBeforeLoad : function(combo,opts){
1138 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1140 this.restrictHeight();
1141 this.selectedIndex = -1;
1145 onLoad : function(){
1147 this.hasQuery = false;
1153 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1154 this.loading.hide();
1157 if(this.store.getCount() > 0){
1160 this.restrictHeight();
1161 if(this.lastQuery == this.allQuery){
1162 if(this.editable && !this.tickable){
1163 this.inputEl().dom.select();
1167 !this.selectByValue(this.value, true) &&
1170 !this.store.lastOptions ||
1171 typeof(this.store.lastOptions.add) == 'undefined' ||
1172 this.store.lastOptions.add != true
1175 this.select(0, true);
1181 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1182 this.taTask.delay(this.typeAheadDelay);
1186 this.onEmptyResults();
1192 onLoadException : function()
1194 this.hasQuery = false;
1196 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1197 this.loading.hide();
1200 if(this.tickable && this.editable){
1205 // only causes errors at present
1206 //Roo.log(this.store.reader.jsonData);
1207 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1209 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1215 onTypeAhead : function(){
1216 if(this.store.getCount() > 0){
1217 var r = this.store.getAt(0);
1218 var newValue = r.data[this.displayField];
1219 var len = newValue.length;
1220 var selStart = this.getRawValue().length;
1222 if(selStart != len){
1223 this.setRawValue(newValue);
1224 this.selectText(selStart, newValue.length);
1230 onSelect : function(record, index){
1232 if(this.fireEvent('beforeselect', this, record, index) !== false){
1234 this.setFromData(index > -1 ? record.data : false);
1237 this.fireEvent('select', this, record, index);
1242 * Returns the currently selected field value or empty string if no value is set.
1243 * @return {String} value The selected value
1245 getValue : function()
1247 if(Roo.isIOS && this.useNativeIOS){
1248 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1252 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1255 if(this.valueField){
1256 return typeof this.value != 'undefined' ? this.value : '';
1258 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1262 getRawValue : function()
1264 if(Roo.isIOS && this.useNativeIOS){
1265 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1268 var v = this.inputEl().getValue();
1274 * Clears any text/value currently set in the field
1276 clearValue : function(){
1278 if(this.hiddenField){
1279 this.hiddenField.dom.value = '';
1282 this.setRawValue('');
1283 this.lastSelectionText = '';
1284 this.lastData = false;
1286 var close = this.closeTriggerEl();
1297 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1298 * will be displayed in the field. If the value does not match the data value of an existing item,
1299 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1300 * Otherwise the field will be blank (although the value will still be set).
1301 * @param {String} value The value to match
1303 setValue : function(v)
1305 if(Roo.isIOS && this.useNativeIOS){
1306 this.setIOSValue(v);
1316 if(this.valueField){
1317 var r = this.findRecord(this.valueField, v);
1319 text = r.data[this.displayField];
1320 }else if(this.valueNotFoundText !== undefined){
1321 text = this.valueNotFoundText;
1324 this.lastSelectionText = text;
1325 if(this.hiddenField){
1326 this.hiddenField.dom.value = v;
1328 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1331 var close = this.closeTriggerEl();
1334 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1340 * @property {Object} the last set data for the element
1345 * Sets the value of the field based on a object which is related to the record format for the store.
1346 * @param {Object} value the value to set as. or false on reset?
1348 setFromData : function(o){
1355 var dv = ''; // display value
1356 var vv = ''; // value value..
1358 if (this.displayField) {
1359 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1361 // this is an error condition!!!
1362 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1365 if(this.valueField){
1366 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1369 var close = this.closeTriggerEl();
1372 if(dv.length || vv * 1 > 0){
1374 this.blockFocus=true;
1380 if(this.hiddenField){
1381 this.hiddenField.dom.value = vv;
1383 this.lastSelectionText = dv;
1384 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1388 // no hidden field.. - we store the value in 'value', but still display
1389 // display field!!!!
1390 this.lastSelectionText = dv;
1391 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1399 // overridden so that last data is reset..
1406 this.setValue(this.originalValue);
1407 //this.clearInvalid();
1408 this.lastData = false;
1410 this.view.clearSelections();
1416 findRecord : function(prop, value){
1418 if(this.store.getCount() > 0){
1419 this.store.each(function(r){
1420 if(r.data[prop] == value){
1432 // returns hidden if it's set..
1433 if (!this.rendered) {return ''};
1434 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1438 onViewMove : function(e, t){
1439 this.inKeyMode = false;
1443 onViewOver : function(e, t){
1444 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1447 var item = this.view.findItemFromChild(t);
1450 var index = this.view.indexOf(item);
1451 this.select(index, false);
1456 onViewClick : function(view, doFocus, el, e)
1458 var index = this.view.getSelectedIndexes()[0];
1460 var r = this.store.getAt(index);
1464 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1471 Roo.each(this.tickItems, function(v,k){
1473 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1475 _this.tickItems.splice(k, 1);
1477 if(typeof(e) == 'undefined' && view == false){
1478 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1490 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1491 this.tickItems.push(r.data);
1494 if(typeof(e) == 'undefined' && view == false){
1495 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1502 this.onSelect(r, index);
1504 if(doFocus !== false && !this.blockFocus){
1505 this.inputEl().focus();
1510 restrictHeight : function(){
1511 //this.innerList.dom.style.height = '';
1512 //var inner = this.innerList.dom;
1513 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1514 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1515 //this.list.beginUpdate();
1516 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1517 this.list.alignTo(this.inputEl(), this.listAlign);
1518 this.list.alignTo(this.inputEl(), this.listAlign);
1519 //this.list.endUpdate();
1523 onEmptyResults : function(){
1525 if(this.tickable && this.editable){
1526 this.hasFocus = false;
1527 this.restrictHeight();
1535 * Returns true if the dropdown list is expanded, else false.
1537 isExpanded : function(){
1538 return this.list.isVisible();
1542 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1543 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1544 * @param {String} value The data value of the item to select
1545 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1546 * selected item if it is not currently in view (defaults to true)
1547 * @return {Boolean} True if the value matched an item in the list, else false
1549 selectByValue : function(v, scrollIntoView){
1550 if(v !== undefined && v !== null){
1551 var r = this.findRecord(this.valueField || this.displayField, v);
1553 this.select(this.store.indexOf(r), scrollIntoView);
1561 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1562 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1563 * @param {Number} index The zero-based index of the list item to select
1564 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1565 * selected item if it is not currently in view (defaults to true)
1567 select : function(index, scrollIntoView){
1568 this.selectedIndex = index;
1569 this.view.select(index);
1570 if(scrollIntoView !== false){
1571 var el = this.view.getNode(index);
1573 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1576 this.list.scrollChildIntoView(el, false);
1582 selectNext : function(){
1583 var ct = this.store.getCount();
1585 if(this.selectedIndex == -1){
1587 }else if(this.selectedIndex < ct-1){
1588 this.select(this.selectedIndex+1);
1594 selectPrev : function(){
1595 var ct = this.store.getCount();
1597 if(this.selectedIndex == -1){
1599 }else if(this.selectedIndex != 0){
1600 this.select(this.selectedIndex-1);
1606 onKeyUp : function(e){
1607 if(this.editable !== false && !e.isSpecialKey()){
1608 this.lastKey = e.getKey();
1609 this.dqTask.delay(this.queryDelay);
1614 validateBlur : function(){
1615 return !this.list || !this.list.isVisible();
1619 initQuery : function(){
1621 var v = this.getRawValue();
1623 if(this.tickable && this.editable){
1624 v = this.tickableInputEl().getValue();
1631 doForce : function(){
1632 if(this.inputEl().dom.value.length > 0){
1633 this.inputEl().dom.value =
1634 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1640 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1641 * query allowing the query action to be canceled if needed.
1642 * @param {String} query The SQL query to execute
1643 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1644 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1645 * saved in the current store (defaults to false)
1647 doQuery : function(q, forceAll){
1649 if(q === undefined || q === null){
1658 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1663 forceAll = qe.forceAll;
1664 if(forceAll === true || (q.length >= this.minChars)){
1666 this.hasQuery = true;
1668 if(this.lastQuery != q || this.alwaysQuery){
1670 if(this.mode == 'local'){
1671 this.selectedIndex = -1;
1673 this.store.clearFilter();
1676 if(this.specialFilter){
1677 this.fireEvent('specialfilter', this);
1682 this.store.filter(this.displayField, q);
1685 this.store.fireEvent("datachanged", this.store);
1692 this.store.baseParams[this.queryParam] = q;
1694 var options = {params : this.getParams(q)};
1698 options.params.start = this.page * this.pageSize;
1701 this.store.load(options);
1704 * this code will make the page width larger, at the beginning, the list not align correctly,
1705 * we should expand the list on onLoad
1711 this.selectedIndex = -1;
1716 this.loadNext = false;
1720 getParams : function(q){
1722 //p[this.queryParam] = q;
1726 p.limit = this.pageSize;
1732 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1734 collapse : function(){
1735 if(!this.isExpanded()){
1741 this.hasFocus = false;
1745 this.cancelBtn.hide();
1746 this.trigger.show();
1749 this.tickableInputEl().dom.value = '';
1750 this.tickableInputEl().blur();
1755 Roo.get(document).un('mousedown', this.collapseIf, this);
1756 Roo.get(document).un('mousewheel', this.collapseIf, this);
1757 if (!this.editable) {
1758 Roo.get(document).un('keydown', this.listKeyPress, this);
1760 this.fireEvent('collapse', this);
1766 collapseIf : function(e){
1767 var in_combo = e.within(this.el);
1768 var in_list = e.within(this.list);
1769 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1771 if (in_combo || in_list || is_list) {
1772 //e.stopPropagation();
1777 this.onTickableFooterButtonClick(e, false, false);
1785 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1787 expand : function(){
1789 if(this.isExpanded() || !this.hasFocus){
1793 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1794 this.list.setWidth(lw);
1800 this.restrictHeight();
1804 this.tickItems = Roo.apply([], this.item);
1807 this.cancelBtn.show();
1808 this.trigger.hide();
1811 this.tickableInputEl().focus();
1816 Roo.get(document).on('mousedown', this.collapseIf, this);
1817 Roo.get(document).on('mousewheel', this.collapseIf, this);
1818 if (!this.editable) {
1819 Roo.get(document).on('keydown', this.listKeyPress, this);
1822 this.fireEvent('expand', this);
1826 // Implements the default empty TriggerField.onTriggerClick function
1827 onTriggerClick : function(e)
1829 Roo.log('trigger click');
1831 if(this.disabled || !this.triggerList){
1836 this.loadNext = false;
1838 if(this.isExpanded()){
1840 if (!this.blockFocus) {
1841 this.inputEl().focus();
1845 this.hasFocus = true;
1846 if(this.triggerAction == 'all') {
1847 this.doQuery(this.allQuery, true);
1849 this.doQuery(this.getRawValue());
1851 if (!this.blockFocus) {
1852 this.inputEl().focus();
1857 onTickableTriggerClick : function(e)
1864 this.loadNext = false;
1865 this.hasFocus = true;
1867 if(this.triggerAction == 'all') {
1868 this.doQuery(this.allQuery, true);
1870 this.doQuery(this.getRawValue());
1874 onSearchFieldClick : function(e)
1876 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1877 this.onTickableFooterButtonClick(e, false, false);
1881 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1886 this.loadNext = false;
1887 this.hasFocus = true;
1889 if(this.triggerAction == 'all') {
1890 this.doQuery(this.allQuery, true);
1892 this.doQuery(this.getRawValue());
1896 listKeyPress : function(e)
1898 //Roo.log('listkeypress');
1899 // scroll to first matching element based on key pres..
1900 if (e.isSpecialKey()) {
1903 var k = String.fromCharCode(e.getKey()).toUpperCase();
1906 var csel = this.view.getSelectedNodes();
1907 var cselitem = false;
1909 var ix = this.view.indexOf(csel[0]);
1910 cselitem = this.store.getAt(ix);
1911 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1917 this.store.each(function(v) {
1919 // start at existing selection.
1920 if (cselitem.id == v.id) {
1926 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1927 match = this.store.indexOf(v);
1933 if (match === false) {
1934 return true; // no more action?
1937 this.view.select(match);
1938 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1939 sn.scrollIntoView(sn.dom.parentNode, false);
1942 onViewScroll : function(e, t){
1944 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){
1948 this.hasQuery = true;
1950 this.loading = this.list.select('.loading', true).first();
1952 if(this.loading === null){
1953 this.list.createChild({
1955 cls: 'loading roo-select2-more-results roo-select2-active',
1956 html: 'Loading more results...'
1959 this.loading = this.list.select('.loading', true).first();
1961 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1963 this.loading.hide();
1966 this.loading.show();
1971 this.loadNext = true;
1973 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1978 addItem : function(o)
1980 var dv = ''; // display value
1982 if (this.displayField) {
1983 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1985 // this is an error condition!!!
1986 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1993 var choice = this.choices.createChild({
1995 cls: 'roo-select2-search-choice',
2004 cls: 'roo-select2-search-choice-close fa fa-times',
2009 }, this.searchField);
2011 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2013 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2021 this.inputEl().dom.value = '';
2026 onRemoveItem : function(e, _self, o)
2030 this.lastItem = Roo.apply([], this.item);
2032 var index = this.item.indexOf(o.data) * 1;
2035 Roo.log('not this item?!');
2039 this.item.splice(index, 1);
2044 this.fireEvent('remove', this, e);
2050 syncValue : function()
2052 if(!this.item.length){
2059 Roo.each(this.item, function(i){
2060 if(_this.valueField){
2061 value.push(i[_this.valueField]);
2068 this.value = value.join(',');
2070 if(this.hiddenField){
2071 this.hiddenField.dom.value = this.value;
2074 this.store.fireEvent("datachanged", this.store);
2079 clearItem : function()
2087 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2095 if(this.tickable && !Roo.isTouch){
2096 this.view.refresh();
2100 inputEl: function ()
2102 if(Roo.isIOS && this.useNativeIOS){
2103 return this.el.select('select.roo-ios-select', true).first();
2106 if(Roo.isTouch && this.mobileTouchView){
2107 return this.el.select('input.form-control',true).first();
2111 return this.searchField;
2114 return this.el.select('input.form-control',true).first();
2117 onTickableFooterButtonClick : function(e, btn, el)
2121 this.lastItem = Roo.apply([], this.item);
2123 if(btn && btn.name == 'cancel'){
2124 this.tickItems = Roo.apply([], this.item);
2133 Roo.each(this.tickItems, function(o){
2141 validate : function()
2143 if(this.getVisibilityEl().hasClass('hidden')){
2147 var v = this.getRawValue();
2150 v = this.getValue();
2153 if(this.disabled || this.allowBlank || v.length){
2162 tickableInputEl : function()
2164 if(!this.tickable || !this.editable){
2165 return this.inputEl();
2168 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2172 getAutoCreateTouchView : function()
2177 cls: 'form-group' //input-group
2183 type : this.inputType,
2184 cls : 'form-control x-combo-noedit',
2185 autocomplete: 'new-password',
2186 placeholder : this.placeholder || '',
2191 input.name = this.name;
2195 input.cls += ' input-' + this.size;
2198 if (this.disabled) {
2199 input.disabled = true;
2210 inputblock.cls += ' input-group';
2212 inputblock.cn.unshift({
2214 cls : 'input-group-addon',
2219 if(this.removable && !this.multiple){
2220 inputblock.cls += ' roo-removable';
2222 inputblock.cn.push({
2225 cls : 'roo-combo-removable-btn close'
2229 if(this.hasFeedback && !this.allowBlank){
2231 inputblock.cls += ' has-feedback';
2233 inputblock.cn.push({
2235 cls: 'glyphicon form-control-feedback'
2242 inputblock.cls += (this.before) ? '' : ' input-group';
2244 inputblock.cn.push({
2246 cls : 'input-group-addon',
2257 cls: 'form-hidden-field'
2271 cls: 'form-hidden-field'
2275 cls: 'roo-select2-choices',
2279 cls: 'roo-select2-search-field',
2292 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2298 if(!this.multiple && this.showToggleBtn){
2305 if (this.caret != false) {
2308 cls: 'fa fa-' + this.caret
2315 cls : 'input-group-addon btn dropdown-toggle',
2320 cls: 'combobox-clear',
2334 combobox.cls += ' roo-select2-container-multi';
2337 var align = this.labelAlign || this.parentLabelAlign();
2339 if (align ==='left' && this.fieldLabel.length) {
2344 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2345 tooltip : 'This field is required'
2349 cls : 'control-label',
2350 html : this.fieldLabel
2361 var labelCfg = cfg.cn[1];
2362 var contentCfg = cfg.cn[2];
2365 if(this.indicatorpos == 'right'){
2370 cls : 'control-label',
2374 html : this.fieldLabel
2378 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2379 tooltip : 'This field is required'
2392 labelCfg = cfg.cn[0];
2393 contentCfg = cfg.cn[1];
2398 if(this.labelWidth > 12){
2399 labelCfg.style = "width: " + this.labelWidth + 'px';
2402 if(this.labelWidth < 13 && this.labelmd == 0){
2403 this.labelmd = this.labelWidth;
2406 if(this.labellg > 0){
2407 labelCfg.cls += ' col-lg-' + this.labellg;
2408 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2411 if(this.labelmd > 0){
2412 labelCfg.cls += ' col-md-' + this.labelmd;
2413 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2416 if(this.labelsm > 0){
2417 labelCfg.cls += ' col-sm-' + this.labelsm;
2418 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2421 if(this.labelxs > 0){
2422 labelCfg.cls += ' col-xs-' + this.labelxs;
2423 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2427 } else if ( this.fieldLabel.length) {
2431 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2432 tooltip : 'This field is required'
2436 cls : 'control-label',
2437 html : this.fieldLabel
2448 if(this.indicatorpos == 'right'){
2452 cls : 'control-label',
2453 html : this.fieldLabel,
2457 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2458 tooltip : 'This field is required'
2475 var settings = this;
2477 ['xs','sm','md','lg'].map(function(size){
2478 if (settings[size]) {
2479 cfg.cls += ' col-' + size + '-' + settings[size];
2486 initTouchView : function()
2488 this.renderTouchView();
2490 this.touchViewEl.on('scroll', function(){
2491 this.el.dom.scrollTop = 0;
2494 this.originalValue = this.getValue();
2496 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2498 this.inputEl().on("click", this.showTouchView, this);
2499 if (this.triggerEl) {
2500 this.triggerEl.on("click", this.showTouchView, this);
2504 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2505 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2507 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2509 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2510 this.store.on('load', this.onTouchViewLoad, this);
2511 this.store.on('loadexception', this.onTouchViewLoadException, this);
2513 if(this.hiddenName){
2515 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2517 this.hiddenField.dom.value =
2518 this.hiddenValue !== undefined ? this.hiddenValue :
2519 this.value !== undefined ? this.value : '';
2521 this.el.dom.removeAttribute('name');
2522 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2526 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2527 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2530 if(this.removable && !this.multiple){
2531 var close = this.closeTriggerEl();
2533 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2534 close.on('click', this.removeBtnClick, this, close);
2538 * fix the bug in Safari iOS8
2540 this.inputEl().on("focus", function(e){
2541 document.activeElement.blur();
2544 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2551 renderTouchView : function()
2553 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2554 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2556 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2557 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2559 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2560 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2561 this.touchViewBodyEl.setStyle('overflow', 'auto');
2563 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2564 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2566 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2567 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2571 showTouchView : function()
2577 this.touchViewHeaderEl.hide();
2579 if(this.modalTitle.length){
2580 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2581 this.touchViewHeaderEl.show();
2584 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2585 this.touchViewEl.show();
2587 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2589 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2590 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2592 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2594 if(this.modalTitle.length){
2595 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2598 this.touchViewBodyEl.setHeight(bodyHeight);
2602 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2604 this.touchViewEl.addClass('in');
2607 if(this._touchViewMask){
2608 Roo.get(document.body).addClass("x-body-masked");
2609 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2610 this._touchViewMask.setStyle('z-index', 10000);
2611 this._touchViewMask.addClass('show');
2614 this.doTouchViewQuery();
2618 hideTouchView : function()
2620 this.touchViewEl.removeClass('in');
2624 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2626 this.touchViewEl.setStyle('display', 'none');
2629 if(this._touchViewMask){
2630 this._touchViewMask.removeClass('show');
2631 Roo.get(document.body).removeClass("x-body-masked");
2635 setTouchViewValue : function()
2642 Roo.each(this.tickItems, function(o){
2647 this.hideTouchView();
2650 doTouchViewQuery : function()
2659 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2663 if(!this.alwaysQuery || this.mode == 'local'){
2664 this.onTouchViewLoad();
2671 onTouchViewBeforeLoad : function(combo,opts)
2677 onTouchViewLoad : function()
2679 if(this.store.getCount() < 1){
2680 this.onTouchViewEmptyResults();
2684 this.clearTouchView();
2686 var rawValue = this.getRawValue();
2688 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2690 this.tickItems = [];
2692 this.store.data.each(function(d, rowIndex){
2693 var row = this.touchViewListGroup.createChild(template);
2695 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2696 row.addClass(d.data.cls);
2699 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2702 html : d.data[this.displayField]
2705 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2706 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2709 row.removeClass('selected');
2710 if(!this.multiple && this.valueField &&
2711 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2714 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2715 row.addClass('selected');
2718 if(this.multiple && this.valueField &&
2719 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2723 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2724 this.tickItems.push(d.data);
2727 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2731 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2733 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2735 if(this.modalTitle.length){
2736 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2739 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb');
2741 if(this.mobile_restrict_height && listHeight < bodyHeight){
2742 this.touchViewBodyEl.setHeight(listHeight);
2747 if(firstChecked && listHeight > bodyHeight){
2748 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2753 onTouchViewLoadException : function()
2755 this.hideTouchView();
2758 onTouchViewEmptyResults : function()
2760 this.clearTouchView();
2762 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2764 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2768 clearTouchView : function()
2770 this.touchViewListGroup.dom.innerHTML = '';
2773 onTouchViewClick : function(e, el, o)
2778 var rowIndex = o.rowIndex;
2780 var r = this.store.getAt(rowIndex);
2782 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2785 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2786 c.dom.removeAttribute('checked');
2789 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2791 this.setFromData(r.data);
2793 var close = this.closeTriggerEl();
2799 this.hideTouchView();
2801 this.fireEvent('select', this, r, rowIndex);
2806 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2807 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2808 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2812 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2813 this.addItem(r.data);
2814 this.tickItems.push(r.data);
2818 getAutoCreateNativeIOS : function()
2821 cls: 'form-group' //input-group,
2826 cls : 'roo-ios-select'
2830 combobox.name = this.name;
2833 if (this.disabled) {
2834 combobox.disabled = true;
2837 var settings = this;
2839 ['xs','sm','md','lg'].map(function(size){
2840 if (settings[size]) {
2841 cfg.cls += ' col-' + size + '-' + settings[size];
2851 initIOSView : function()
2853 this.store.on('load', this.onIOSViewLoad, this);
2858 onIOSViewLoad : function()
2860 if(this.store.getCount() < 1){
2864 this.clearIOSView();
2866 if(this.allowBlank) {
2868 var default_text = '-- SELECT --';
2870 if(this.placeholder.length){
2871 default_text = this.placeholder;
2874 if(this.emptyTitle.length){
2875 default_text += ' - ' + this.emptyTitle + ' -';
2878 var opt = this.inputEl().createChild({
2885 o[this.valueField] = 0;
2886 o[this.displayField] = default_text;
2888 this.ios_options.push({
2895 this.store.data.each(function(d, rowIndex){
2899 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2900 html = d.data[this.displayField];
2905 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2906 value = d.data[this.valueField];
2915 if(this.value == d.data[this.valueField]){
2916 option['selected'] = true;
2919 var opt = this.inputEl().createChild(option);
2921 this.ios_options.push({
2928 this.inputEl().on('change', function(){
2929 this.fireEvent('select', this);
2934 clearIOSView: function()
2936 this.inputEl().dom.innerHTML = '';
2938 this.ios_options = [];
2941 setIOSValue: function(v)
2945 if(!this.ios_options){
2949 Roo.each(this.ios_options, function(opts){
2951 opts.el.dom.removeAttribute('selected');
2953 if(opts.data[this.valueField] != v){
2957 opts.el.dom.setAttribute('selected', true);
2963 * @cfg {Boolean} grow
2967 * @cfg {Number} growMin
2971 * @cfg {Number} growMax
2980 Roo.apply(Roo.bootstrap.ComboBox, {
2984 cls: 'modal-header',
3006 cls: 'list-group-item',
3010 cls: 'roo-combobox-list-group-item-value'
3014 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3028 listItemCheckbox : {
3030 cls: 'list-group-item',
3034 cls: 'roo-combobox-list-group-item-value'
3038 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3054 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3059 cls: 'modal-footer',
3067 cls: 'col-xs-6 text-left',
3070 cls: 'btn btn-danger roo-touch-view-cancel',
3076 cls: 'col-xs-6 text-right',
3079 cls: 'btn btn-success roo-touch-view-ok',
3090 Roo.apply(Roo.bootstrap.ComboBox, {
3092 touchViewTemplate : {
3094 cls: 'modal fade roo-combobox-touch-view',
3098 cls: 'modal-dialog',
3099 style : 'position:fixed', // we have to fix position....
3103 cls: 'modal-content',
3105 Roo.bootstrap.ComboBox.header,
3106 Roo.bootstrap.ComboBox.body,
3107 Roo.bootstrap.ComboBox.footer