7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
19 * @cfg {String} emptyTitle default ''
21 * Create a new ComboBox.
22 * @param {Object} config Configuration options
24 Roo.bootstrap.ComboBox = function(config){
25 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
29 * Fires when the dropdown list is expanded
30 * @param {Roo.bootstrap.ComboBox} combo This combo box
35 * Fires when the dropdown list is collapsed
36 * @param {Roo.bootstrap.ComboBox} combo This combo box
41 * Fires before a list item is selected. Return false to cancel the selection.
42 * @param {Roo.bootstrap.ComboBox} combo This combo box
43 * @param {Roo.data.Record} record The data record returned from the underlying store
44 * @param {Number} index The index of the selected item in the dropdown list
46 'beforeselect' : true,
49 * Fires when a list item is selected
50 * @param {Roo.bootstrap.ComboBox} combo This combo box
51 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
52 * @param {Number} index The index of the selected item in the dropdown list
57 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
58 * The event object passed has these properties:
59 * @param {Roo.bootstrap.ComboBox} combo This combo box
60 * @param {String} query The query
61 * @param {Boolean} forceAll true to force "all" query
62 * @param {Boolean} cancel true to cancel the query
63 * @param {Object} e The query event object
68 * Fires when the 'add' icon is pressed (add a listener to enable add button)
69 * @param {Roo.bootstrap.ComboBox} combo This combo box
74 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
75 * @param {Roo.bootstrap.ComboBox} combo This combo box
76 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
81 * Fires when the remove value from the combobox array
82 * @param {Roo.bootstrap.ComboBox} combo This combo box
87 * Fires when the remove value from the combobox array
88 * @param {Roo.bootstrap.ComboBox} combo This combo box
92 * @event specialfilter
93 * Fires when specialfilter
94 * @param {Roo.bootstrap.ComboBox} combo This combo box
96 'specialfilter' : true,
99 * Fires when tick the element
100 * @param {Roo.bootstrap.ComboBox} combo This combo box
104 * @event touchviewdisplay
105 * Fires when touch view require special display (default is using displayField)
106 * @param {Roo.bootstrap.ComboBox} combo This combo box
107 * @param {Object} cfg set html .
109 'touchviewdisplay' : true
116 this.selectedIndex = -1;
117 if(this.mode == 'local'){
118 if(config.queryDelay === undefined){
119 this.queryDelay = 10;
121 if(config.minChars === undefined){
127 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
130 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
131 * rendering into an Roo.Editor, defaults to false)
134 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
135 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
138 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
141 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
142 * the dropdown list (defaults to undefined, with no header element)
146 * @cfg {String/Roo.Template} tpl The template to use to render the output
150 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
152 listWidth: undefined,
154 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
155 * mode = 'remote' or 'text' if mode = 'local')
157 displayField: undefined,
160 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
161 * mode = 'remote' or 'value' if mode = 'local').
162 * Note: use of a valueField requires the user make a selection
163 * in order for a value to be mapped.
165 valueField: undefined,
167 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
172 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
173 * field's data value (defaults to the underlying DOM element's name)
175 hiddenName: undefined,
177 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
181 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
183 selectedClass: 'active',
186 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
190 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
191 * anchor positions (defaults to 'tl-bl')
195 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
199 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
200 * query specified by the allQuery config option (defaults to 'query')
202 triggerAction: 'query',
204 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
205 * (defaults to 4, does not apply if editable = false)
209 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
210 * delay (typeAheadDelay) if it matches a known value (defaults to false)
214 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
215 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
219 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
220 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
224 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
225 * when editable = true (defaults to false)
229 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
233 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
234 * when mode = 'remote' (defaults to 'Loading...')
236 loadingText: 'Loading...',
238 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
242 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
246 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
247 * traditional select (defaults to true)
251 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
255 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
259 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
260 * listWidth has a higher value)
264 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
265 * allow the user to set arbitrary text into the field (defaults to false)
267 forceSelection:false,
269 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
270 * if typeAhead = true (defaults to 250)
272 typeAheadDelay : 250,
274 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
275 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
277 valueNotFoundText : undefined,
279 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
284 * @cfg {Boolean} disableClear Disable showing of clear button.
286 disableClear : false,
288 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
293 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
298 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
300 invalidClass : "has-warning",
303 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
305 validClass : "has-success",
308 * @cfg {Boolean} specialFilter (true|false) special filter default false
310 specialFilter : false,
313 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
315 mobileTouchView : true,
318 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
320 useNativeIOS : false,
334 btnPosition : 'right',
336 showToggleBtn : true,
338 emptyResultText: 'Empty',
339 triggerText : 'Select',
342 // element that contains real text value.. (when hidden is used..)
344 getAutoCreate : function()
349 * Render classic select for iso
352 if(Roo.isIOS && this.useNativeIOS){
353 cfg = this.getAutoCreateNativeIOS();
361 if(Roo.isTouch && this.mobileTouchView){
362 cfg = this.getAutoCreateTouchView();
370 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
375 * ComboBox with tickable selections
378 var align = this.labelAlign || this.parentLabelAlign();
381 cls : 'form-group roo-combobox-tickable' //input-group
384 var btn_text_select = '';
385 var btn_text_done = '';
386 var btn_text_cancel = '';
388 if (this.btn_text_show) {
389 btn_text_select = 'Select';
390 btn_text_done = 'Done';
391 btn_text_cancel = 'Cancel';
396 cls : 'tickable-buttons',
401 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
402 //html : this.triggerText
403 html: btn_text_select
409 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
417 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
419 html: btn_text_cancel
427 cls: 'roo-select2-search-field-input'
433 Roo.each(buttons.cn, function(c){
435 c.cls += ' btn-' + _this.size;
438 if (_this.disabled) {
449 cls: 'form-hidden-field'
453 cls: 'roo-select2-choices',
457 cls: 'roo-select2-search-field',
468 cls: 'roo-select2-container input-group roo-select2-container-multi',
473 // cls: 'typeahead typeahead-long dropdown-menu',
474 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
479 if(this.hasFeedback && !this.allowBlank){
483 cls: 'glyphicon form-control-feedback'
486 combobox.cn.push(feedback);
490 if (align ==='left' && this.fieldLabel.length) {
492 cfg.cls += ' roo-form-group-label-left';
497 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
498 tooltip : 'This field is required'
503 cls : 'control-label',
504 html : this.fieldLabel
516 var labelCfg = cfg.cn[1];
517 var contentCfg = cfg.cn[2];
520 if(this.indicatorpos == 'right'){
526 cls : 'control-label',
530 html : this.fieldLabel
534 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
535 tooltip : 'This field is required'
550 labelCfg = cfg.cn[0];
551 contentCfg = cfg.cn[1];
555 if(this.labelWidth > 12){
556 labelCfg.style = "width: " + this.labelWidth + 'px';
559 if(this.labelWidth < 13 && this.labelmd == 0){
560 this.labelmd = this.labelWidth;
563 if(this.labellg > 0){
564 labelCfg.cls += ' col-lg-' + this.labellg;
565 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
568 if(this.labelmd > 0){
569 labelCfg.cls += ' col-md-' + this.labelmd;
570 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
573 if(this.labelsm > 0){
574 labelCfg.cls += ' col-sm-' + this.labelsm;
575 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
578 if(this.labelxs > 0){
579 labelCfg.cls += ' col-xs-' + this.labelxs;
580 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
584 } else if ( this.fieldLabel.length) {
585 // Roo.log(" label");
589 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
590 tooltip : 'This field is required'
594 //cls : 'input-group-addon',
595 html : this.fieldLabel
600 if(this.indicatorpos == 'right'){
604 //cls : 'input-group-addon',
605 html : this.fieldLabel
609 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
610 tooltip : 'This field is required'
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 = '<li><a href="#">{' + this.displayField + '}</a></li>';
775 this.view = new Roo.View(this.list, this.tpl, {
776 singleSelect:true, store: this.store, selectedClass: this.selectedClass
778 //this.view.wrapEl.setDisplayed(false);
779 this.view.on('click', this.onViewClick, this);
782 this.store.on('beforeload', this.onBeforeLoad, this);
783 this.store.on('load', this.onLoad, this);
784 this.store.on('loadexception', this.onLoadException, this);
787 this.resizer = new Roo.Resizable(this.list, {
788 pinned:true, handles:'se'
790 this.resizer.on('resize', function(r, w, h){
791 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
793 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
794 this.restrictHeight();
796 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
800 this.editable = true;
801 this.setEditable(false);
806 if (typeof(this.events.add.listeners) != 'undefined') {
808 this.addicon = this.wrap.createChild(
809 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
811 this.addicon.on('click', function(e) {
812 this.fireEvent('add', this);
815 if (typeof(this.events.edit.listeners) != 'undefined') {
817 this.editicon = this.wrap.createChild(
818 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
820 this.editicon.setStyle('margin-left', '40px');
822 this.editicon.on('click', function(e) {
824 // we fire even if inothing is selected..
825 this.fireEvent('edit', this, this.lastData );
831 this.keyNav = new Roo.KeyNav(this.inputEl(), {
833 this.inKeyMode = true;
837 "down" : function(e){
838 if(!this.isExpanded()){
839 this.onTriggerClick();
841 this.inKeyMode = true;
846 "enter" : function(e){
847 // this.onViewClick();
851 if(this.fireEvent("specialkey", this, e)){
852 this.onViewClick(false);
865 if(this.fireEvent("specialkey", this, e)){
866 this.onViewClick(false);
874 doRelay : function(foo, bar, hname){
875 if(hname == 'down' || this.scope.isExpanded()){
876 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
885 this.queryDelay = Math.max(this.queryDelay || 10,
886 this.mode == 'local' ? 10 : 250);
889 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
892 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
894 if(this.editable !== false){
895 this.inputEl().on("keyup", this.onKeyUp, this);
897 if(this.forceSelection){
898 this.inputEl().on('blur', this.doForce, this);
902 this.choices = this.el.select('ul.roo-select2-choices', true).first();
903 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
907 initTickableEvents: function()
913 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
915 this.hiddenField.dom.value =
916 this.hiddenValue !== undefined ? this.hiddenValue :
917 this.value !== undefined ? this.value : '';
919 // prevent input submission
920 this.el.dom.removeAttribute('name');
921 this.hiddenField.dom.setAttribute('name', this.hiddenName);
926 // this.list = this.el.select('ul.dropdown-menu',true).first();
928 this.choices = this.el.select('ul.roo-select2-choices', true).first();
929 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
930 if(this.triggerList){
931 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
934 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
935 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
937 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
938 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
940 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
941 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
943 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
944 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
945 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
948 this.cancelBtn.hide();
953 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
954 _this.list.setWidth(lw);
957 this.list.on('mouseover', this.onViewOver, this);
958 this.list.on('mousemove', this.onViewMove, this);
960 this.list.on('scroll', this.onViewScroll, this);
963 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"; +
964 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
967 this.view = new Roo.View(this.list, this.tpl, {
968 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
971 //this.view.wrapEl.setDisplayed(false);
972 this.view.on('click', this.onViewClick, this);
976 this.store.on('beforeload', this.onBeforeLoad, this);
977 this.store.on('load', this.onLoad, this);
978 this.store.on('loadexception', this.onLoadException, this);
981 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
983 this.inKeyMode = true;
987 "down" : function(e){
988 this.inKeyMode = true;
992 "enter" : function(e){
993 if(this.fireEvent("specialkey", this, e)){
994 this.onViewClick(false);
1000 "esc" : function(e){
1001 this.onTickableFooterButtonClick(e, false, false);
1004 "tab" : function(e){
1005 this.fireEvent("specialkey", this, e);
1007 this.onTickableFooterButtonClick(e, false, false);
1014 doRelay : function(e, fn, key){
1015 if(this.scope.isExpanded()){
1016 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1025 this.queryDelay = Math.max(this.queryDelay || 10,
1026 this.mode == 'local' ? 10 : 250);
1029 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1032 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1035 if(this.editable !== false){
1036 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1039 this.indicator = this.indicatorEl();
1042 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1043 this.indicator.hide();
1048 onDestroy : function(){
1050 this.view.setStore(null);
1051 this.view.el.removeAllListeners();
1052 this.view.el.remove();
1053 this.view.purgeListeners();
1056 this.list.dom.innerHTML = '';
1060 this.store.un('beforeload', this.onBeforeLoad, this);
1061 this.store.un('load', this.onLoad, this);
1062 this.store.un('loadexception', this.onLoadException, this);
1064 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1068 fireKey : function(e){
1069 if(e.isNavKeyPress() && !this.list.isVisible()){
1070 this.fireEvent("specialkey", this, e);
1075 onResize: function(w, h){
1076 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1078 // if(typeof w != 'number'){
1079 // // we do not handle it!?!?
1082 // var tw = this.trigger.getWidth();
1083 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1084 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1086 // this.inputEl().setWidth( this.adjustWidth('input', x));
1088 // //this.trigger.setStyle('left', x+'px');
1090 // if(this.list && this.listWidth === undefined){
1091 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1092 // this.list.setWidth(lw);
1093 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1101 * Allow or prevent the user from directly editing the field text. If false is passed,
1102 * the user will only be able to select from the items defined in the dropdown list. This method
1103 * is the runtime equivalent of setting the 'editable' config option at config time.
1104 * @param {Boolean} value True to allow the user to directly edit the field text
1106 setEditable : function(value){
1107 if(value == this.editable){
1110 this.editable = value;
1112 this.inputEl().dom.setAttribute('readOnly', true);
1113 this.inputEl().on('mousedown', this.onTriggerClick, this);
1114 this.inputEl().addClass('x-combo-noedit');
1116 this.inputEl().dom.setAttribute('readOnly', false);
1117 this.inputEl().un('mousedown', this.onTriggerClick, this);
1118 this.inputEl().removeClass('x-combo-noedit');
1124 onBeforeLoad : function(combo,opts){
1129 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1131 this.restrictHeight();
1132 this.selectedIndex = -1;
1136 onLoad : function(){
1138 this.hasQuery = false;
1144 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1145 this.loading.hide();
1148 if(this.store.getCount() > 0){
1151 this.restrictHeight();
1152 if(this.lastQuery == this.allQuery){
1153 if(this.editable && !this.tickable){
1154 this.inputEl().dom.select();
1158 !this.selectByValue(this.value, true) &&
1161 !this.store.lastOptions ||
1162 typeof(this.store.lastOptions.add) == 'undefined' ||
1163 this.store.lastOptions.add != true
1166 this.select(0, true);
1172 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1173 this.taTask.delay(this.typeAheadDelay);
1177 this.onEmptyResults();
1183 onLoadException : function()
1185 this.hasQuery = false;
1187 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1188 this.loading.hide();
1191 if(this.tickable && this.editable){
1196 // only causes errors at present
1197 //Roo.log(this.store.reader.jsonData);
1198 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1200 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1206 onTypeAhead : function(){
1207 if(this.store.getCount() > 0){
1208 var r = this.store.getAt(0);
1209 var newValue = r.data[this.displayField];
1210 var len = newValue.length;
1211 var selStart = this.getRawValue().length;
1213 if(selStart != len){
1214 this.setRawValue(newValue);
1215 this.selectText(selStart, newValue.length);
1221 onSelect : function(record, index){
1223 if(this.fireEvent('beforeselect', this, record, index) !== false){
1225 this.setFromData(index > -1 ? record.data : false);
1228 this.fireEvent('select', this, record, index);
1233 * Returns the currently selected field value or empty string if no value is set.
1234 * @return {String} value The selected value
1236 getValue : function()
1238 if(Roo.isIOS && this.useNativeIOS){
1239 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1243 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1246 if(this.valueField){
1247 return typeof this.value != 'undefined' ? this.value : '';
1249 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1253 getRawValue : function()
1255 if(Roo.isIOS && this.useNativeIOS){
1256 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1259 var v = this.inputEl().getValue();
1265 * Clears any text/value currently set in the field
1267 clearValue : function(){
1269 if(this.hiddenField){
1270 this.hiddenField.dom.value = '';
1273 this.setRawValue('');
1274 this.lastSelectionText = '';
1275 this.lastData = false;
1277 var close = this.closeTriggerEl();
1288 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1289 * will be displayed in the field. If the value does not match the data value of an existing item,
1290 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1291 * Otherwise the field will be blank (although the value will still be set).
1292 * @param {String} value The value to match
1294 setValue : function(v)
1296 if(Roo.isIOS && this.useNativeIOS){
1297 this.setIOSValue(v);
1307 if(this.valueField){
1308 var r = this.findRecord(this.valueField, v);
1310 text = r.data[this.displayField];
1311 }else if(this.valueNotFoundText !== undefined){
1312 text = this.valueNotFoundText;
1315 this.lastSelectionText = text;
1316 if(this.hiddenField){
1317 this.hiddenField.dom.value = v;
1319 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1322 var close = this.closeTriggerEl();
1325 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1331 * @property {Object} the last set data for the element
1336 * Sets the value of the field based on a object which is related to the record format for the store.
1337 * @param {Object} value the value to set as. or false on reset?
1339 setFromData : function(o){
1346 var dv = ''; // display value
1347 var vv = ''; // value value..
1349 if (this.displayField) {
1350 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1352 // this is an error condition!!!
1353 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1356 if(this.valueField){
1357 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1360 var close = this.closeTriggerEl();
1363 if(dv.length || vv * 1 > 0){
1365 this.blockFocus=true;
1371 if(this.hiddenField){
1372 this.hiddenField.dom.value = vv;
1374 this.lastSelectionText = dv;
1375 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1379 // no hidden field.. - we store the value in 'value', but still display
1380 // display field!!!!
1381 this.lastSelectionText = dv;
1382 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1390 // overridden so that last data is reset..
1397 this.setValue(this.originalValue);
1398 //this.clearInvalid();
1399 this.lastData = false;
1401 this.view.clearSelections();
1407 findRecord : function(prop, value){
1409 if(this.store.getCount() > 0){
1410 this.store.each(function(r){
1411 if(r.data[prop] == value){
1423 // returns hidden if it's set..
1424 if (!this.rendered) {return ''};
1425 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1429 onViewMove : function(e, t){
1430 this.inKeyMode = false;
1434 onViewOver : function(e, t){
1435 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1438 var item = this.view.findItemFromChild(t);
1441 var index = this.view.indexOf(item);
1442 this.select(index, false);
1447 onViewClick : function(view, doFocus, el, e)
1449 var index = this.view.getSelectedIndexes()[0];
1451 var r = this.store.getAt(index);
1455 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1462 Roo.each(this.tickItems, function(v,k){
1464 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1466 _this.tickItems.splice(k, 1);
1468 if(typeof(e) == 'undefined' && view == false){
1469 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1481 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1482 this.tickItems.push(r.data);
1485 if(typeof(e) == 'undefined' && view == false){
1486 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1493 this.onSelect(r, index);
1495 if(doFocus !== false && !this.blockFocus){
1496 this.inputEl().focus();
1501 restrictHeight : function(){
1502 //this.innerList.dom.style.height = '';
1503 //var inner = this.innerList.dom;
1504 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1505 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1506 //this.list.beginUpdate();
1507 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1508 this.list.alignTo(this.inputEl(), this.listAlign);
1509 this.list.alignTo(this.inputEl(), this.listAlign);
1510 //this.list.endUpdate();
1514 onEmptyResults : function(){
1516 if(this.tickable && this.editable){
1517 this.hasFocus = false;
1518 this.restrictHeight();
1526 * Returns true if the dropdown list is expanded, else false.
1528 isExpanded : function(){
1529 return this.list.isVisible();
1533 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1534 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1535 * @param {String} value The data value of the item to select
1536 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1537 * selected item if it is not currently in view (defaults to true)
1538 * @return {Boolean} True if the value matched an item in the list, else false
1540 selectByValue : function(v, scrollIntoView){
1541 if(v !== undefined && v !== null){
1542 var r = this.findRecord(this.valueField || this.displayField, v);
1544 this.select(this.store.indexOf(r), scrollIntoView);
1552 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1553 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1554 * @param {Number} index The zero-based index of the list item to select
1555 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1556 * selected item if it is not currently in view (defaults to true)
1558 select : function(index, scrollIntoView){
1559 this.selectedIndex = index;
1560 this.view.select(index);
1561 if(scrollIntoView !== false){
1562 var el = this.view.getNode(index);
1564 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1567 this.list.scrollChildIntoView(el, false);
1573 selectNext : function(){
1574 var ct = this.store.getCount();
1576 if(this.selectedIndex == -1){
1578 }else if(this.selectedIndex < ct-1){
1579 this.select(this.selectedIndex+1);
1585 selectPrev : function(){
1586 var ct = this.store.getCount();
1588 if(this.selectedIndex == -1){
1590 }else if(this.selectedIndex != 0){
1591 this.select(this.selectedIndex-1);
1597 onKeyUp : function(e){
1598 if(this.editable !== false && !e.isSpecialKey()){
1599 this.lastKey = e.getKey();
1600 this.dqTask.delay(this.queryDelay);
1605 validateBlur : function(){
1606 return !this.list || !this.list.isVisible();
1610 initQuery : function(){
1612 var v = this.getRawValue();
1614 if(this.tickable && this.editable){
1615 v = this.tickableInputEl().getValue();
1622 doForce : function(){
1623 if(this.inputEl().dom.value.length > 0){
1624 this.inputEl().dom.value =
1625 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1631 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1632 * query allowing the query action to be canceled if needed.
1633 * @param {String} query The SQL query to execute
1634 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1635 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1636 * saved in the current store (defaults to false)
1638 doQuery : function(q, forceAll){
1640 if(q === undefined || q === null){
1649 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1654 forceAll = qe.forceAll;
1655 if(forceAll === true || (q.length >= this.minChars)){
1657 this.hasQuery = true;
1659 if(this.lastQuery != q || this.alwaysQuery){
1661 if(this.mode == 'local'){
1662 this.selectedIndex = -1;
1664 this.store.clearFilter();
1667 if(this.specialFilter){
1668 this.fireEvent('specialfilter', this);
1673 this.store.filter(this.displayField, q);
1676 this.store.fireEvent("datachanged", this.store);
1683 this.store.baseParams[this.queryParam] = q;
1685 var options = {params : this.getParams(q)};
1689 options.params.start = this.page * this.pageSize;
1692 this.store.load(options);
1695 * this code will make the page width larger, at the beginning, the list not align correctly,
1696 * we should expand the list on onLoad
1702 this.selectedIndex = -1;
1707 this.loadNext = false;
1711 getParams : function(q){
1713 //p[this.queryParam] = q;
1717 p.limit = this.pageSize;
1723 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1725 collapse : function(){
1726 if(!this.isExpanded()){
1732 this.hasFocus = false;
1736 this.cancelBtn.hide();
1737 this.trigger.show();
1740 this.tickableInputEl().dom.value = '';
1741 this.tickableInputEl().blur();
1746 Roo.get(document).un('mousedown', this.collapseIf, this);
1747 Roo.get(document).un('mousewheel', this.collapseIf, this);
1748 if (!this.editable) {
1749 Roo.get(document).un('keydown', this.listKeyPress, this);
1751 this.fireEvent('collapse', this);
1757 collapseIf : function(e){
1758 var in_combo = e.within(this.el);
1759 var in_list = e.within(this.list);
1760 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1762 if (in_combo || in_list || is_list) {
1763 //e.stopPropagation();
1768 this.onTickableFooterButtonClick(e, false, false);
1776 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1778 expand : function(){
1780 if(this.isExpanded() || !this.hasFocus){
1784 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1785 this.list.setWidth(lw);
1791 this.restrictHeight();
1795 this.tickItems = Roo.apply([], this.item);
1798 this.cancelBtn.show();
1799 this.trigger.hide();
1802 this.tickableInputEl().focus();
1807 Roo.get(document).on('mousedown', this.collapseIf, this);
1808 Roo.get(document).on('mousewheel', this.collapseIf, this);
1809 if (!this.editable) {
1810 Roo.get(document).on('keydown', this.listKeyPress, this);
1813 this.fireEvent('expand', this);
1817 // Implements the default empty TriggerField.onTriggerClick function
1818 onTriggerClick : function(e)
1820 Roo.log('trigger click');
1822 if(this.disabled || !this.triggerList){
1827 this.loadNext = false;
1829 if(this.isExpanded()){
1831 if (!this.blockFocus) {
1832 this.inputEl().focus();
1836 this.hasFocus = true;
1837 if(this.triggerAction == 'all') {
1838 this.doQuery(this.allQuery, true);
1840 this.doQuery(this.getRawValue());
1842 if (!this.blockFocus) {
1843 this.inputEl().focus();
1848 onTickableTriggerClick : function(e)
1855 this.loadNext = false;
1856 this.hasFocus = true;
1858 if(this.triggerAction == 'all') {
1859 this.doQuery(this.allQuery, true);
1861 this.doQuery(this.getRawValue());
1865 onSearchFieldClick : function(e)
1867 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1868 this.onTickableFooterButtonClick(e, false, false);
1872 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1877 this.loadNext = false;
1878 this.hasFocus = true;
1880 if(this.triggerAction == 'all') {
1881 this.doQuery(this.allQuery, true);
1883 this.doQuery(this.getRawValue());
1887 listKeyPress : function(e)
1889 //Roo.log('listkeypress');
1890 // scroll to first matching element based on key pres..
1891 if (e.isSpecialKey()) {
1894 var k = String.fromCharCode(e.getKey()).toUpperCase();
1897 var csel = this.view.getSelectedNodes();
1898 var cselitem = false;
1900 var ix = this.view.indexOf(csel[0]);
1901 cselitem = this.store.getAt(ix);
1902 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1908 this.store.each(function(v) {
1910 // start at existing selection.
1911 if (cselitem.id == v.id) {
1917 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1918 match = this.store.indexOf(v);
1924 if (match === false) {
1925 return true; // no more action?
1928 this.view.select(match);
1929 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1930 sn.scrollIntoView(sn.dom.parentNode, false);
1933 onViewScroll : function(e, t){
1935 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){
1939 this.hasQuery = true;
1941 this.loading = this.list.select('.loading', true).first();
1943 if(this.loading === null){
1944 this.list.createChild({
1946 cls: 'loading roo-select2-more-results roo-select2-active',
1947 html: 'Loading more results...'
1950 this.loading = this.list.select('.loading', true).first();
1952 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1954 this.loading.hide();
1957 this.loading.show();
1962 this.loadNext = true;
1964 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1969 addItem : function(o)
1971 var dv = ''; // display value
1973 if (this.displayField) {
1974 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1976 // this is an error condition!!!
1977 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1984 var choice = this.choices.createChild({
1986 cls: 'roo-select2-search-choice',
1995 cls: 'roo-select2-search-choice-close fa fa-times',
2000 }, this.searchField);
2002 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2004 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2012 this.inputEl().dom.value = '';
2017 onRemoveItem : function(e, _self, o)
2021 this.lastItem = Roo.apply([], this.item);
2023 var index = this.item.indexOf(o.data) * 1;
2026 Roo.log('not this item?!');
2030 this.item.splice(index, 1);
2035 this.fireEvent('remove', this, e);
2041 syncValue : function()
2043 if(!this.item.length){
2050 Roo.each(this.item, function(i){
2051 if(_this.valueField){
2052 value.push(i[_this.valueField]);
2059 this.value = value.join(',');
2061 if(this.hiddenField){
2062 this.hiddenField.dom.value = this.value;
2065 this.store.fireEvent("datachanged", this.store);
2070 clearItem : function()
2078 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2086 if(this.tickable && !Roo.isTouch){
2087 this.view.refresh();
2091 inputEl: function ()
2093 if(Roo.isIOS && this.useNativeIOS){
2094 return this.el.select('select.roo-ios-select', true).first();
2097 if(Roo.isTouch && this.mobileTouchView){
2098 return this.el.select('input.form-control',true).first();
2102 return this.searchField;
2105 return this.el.select('input.form-control',true).first();
2108 onTickableFooterButtonClick : function(e, btn, el)
2112 this.lastItem = Roo.apply([], this.item);
2114 if(btn && btn.name == 'cancel'){
2115 this.tickItems = Roo.apply([], this.item);
2124 Roo.each(this.tickItems, function(o){
2132 validate : function()
2134 if(this.getVisibilityEl().hasClass('hidden')){
2138 var v = this.getRawValue();
2141 v = this.getValue();
2144 if(this.disabled || this.allowBlank || v.length){
2153 tickableInputEl : function()
2155 if(!this.tickable || !this.editable){
2156 return this.inputEl();
2159 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2163 getAutoCreateTouchView : function()
2168 cls: 'form-group' //input-group
2174 type : this.inputType,
2175 cls : 'form-control x-combo-noedit',
2176 autocomplete: 'new-password',
2177 placeholder : this.placeholder || '',
2182 input.name = this.name;
2186 input.cls += ' input-' + this.size;
2189 if (this.disabled) {
2190 input.disabled = true;
2201 inputblock.cls += ' input-group';
2203 inputblock.cn.unshift({
2205 cls : 'input-group-addon',
2210 if(this.removable && !this.multiple){
2211 inputblock.cls += ' roo-removable';
2213 inputblock.cn.push({
2216 cls : 'roo-combo-removable-btn close'
2220 if(this.hasFeedback && !this.allowBlank){
2222 inputblock.cls += ' has-feedback';
2224 inputblock.cn.push({
2226 cls: 'glyphicon form-control-feedback'
2233 inputblock.cls += (this.before) ? '' : ' input-group';
2235 inputblock.cn.push({
2237 cls : 'input-group-addon',
2248 cls: 'form-hidden-field'
2262 cls: 'form-hidden-field'
2266 cls: 'roo-select2-choices',
2270 cls: 'roo-select2-search-field',
2283 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2289 if(!this.multiple && this.showToggleBtn){
2296 if (this.caret != false) {
2299 cls: 'fa fa-' + this.caret
2306 cls : 'input-group-addon btn dropdown-toggle',
2311 cls: 'combobox-clear',
2325 combobox.cls += ' roo-select2-container-multi';
2328 var align = this.labelAlign || this.parentLabelAlign();
2330 if (align ==='left' && this.fieldLabel.length) {
2335 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2336 tooltip : 'This field is required'
2340 cls : 'control-label',
2341 html : this.fieldLabel
2352 var labelCfg = cfg.cn[1];
2353 var contentCfg = cfg.cn[2];
2356 if(this.indicatorpos == 'right'){
2361 cls : 'control-label',
2365 html : this.fieldLabel
2369 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2370 tooltip : 'This field is required'
2383 labelCfg = cfg.cn[0];
2384 contentCfg = cfg.cn[1];
2389 if(this.labelWidth > 12){
2390 labelCfg.style = "width: " + this.labelWidth + 'px';
2393 if(this.labelWidth < 13 && this.labelmd == 0){
2394 this.labelmd = this.labelWidth;
2397 if(this.labellg > 0){
2398 labelCfg.cls += ' col-lg-' + this.labellg;
2399 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2402 if(this.labelmd > 0){
2403 labelCfg.cls += ' col-md-' + this.labelmd;
2404 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2407 if(this.labelsm > 0){
2408 labelCfg.cls += ' col-sm-' + this.labelsm;
2409 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2412 if(this.labelxs > 0){
2413 labelCfg.cls += ' col-xs-' + this.labelxs;
2414 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2418 } else if ( this.fieldLabel.length) {
2422 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2423 tooltip : 'This field is required'
2427 cls : 'control-label',
2428 html : this.fieldLabel
2439 if(this.indicatorpos == 'right'){
2443 cls : 'control-label',
2444 html : this.fieldLabel,
2448 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2449 tooltip : 'This field is required'
2466 var settings = this;
2468 ['xs','sm','md','lg'].map(function(size){
2469 if (settings[size]) {
2470 cfg.cls += ' col-' + size + '-' + settings[size];
2477 initTouchView : function()
2479 this.renderTouchView();
2481 this.touchViewEl.on('scroll', function(){
2482 this.el.dom.scrollTop = 0;
2485 this.originalValue = this.getValue();
2487 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2489 this.inputEl().on("click", this.showTouchView, this);
2490 if (this.triggerEl) {
2491 this.triggerEl.on("click", this.showTouchView, this);
2495 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2496 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2498 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2500 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2501 this.store.on('load', this.onTouchViewLoad, this);
2502 this.store.on('loadexception', this.onTouchViewLoadException, this);
2504 if(this.hiddenName){
2506 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2508 this.hiddenField.dom.value =
2509 this.hiddenValue !== undefined ? this.hiddenValue :
2510 this.value !== undefined ? this.value : '';
2512 this.el.dom.removeAttribute('name');
2513 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2517 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2518 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2521 if(this.removable && !this.multiple){
2522 var close = this.closeTriggerEl();
2524 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2525 close.on('click', this.removeBtnClick, this, close);
2529 * fix the bug in Safari iOS8
2531 this.inputEl().on("focus", function(e){
2532 document.activeElement.blur();
2540 renderTouchView : function()
2542 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2543 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2545 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2546 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2548 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2549 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2550 this.touchViewBodyEl.setStyle('overflow', 'auto');
2552 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2553 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2555 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2556 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2560 showTouchView : function()
2566 this.touchViewHeaderEl.hide();
2568 if(this.modalTitle.length){
2569 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2570 this.touchViewHeaderEl.show();
2573 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2574 this.touchViewEl.show();
2576 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2578 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2579 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2581 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2583 if(this.modalTitle.length){
2584 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2587 this.touchViewBodyEl.setHeight(bodyHeight);
2591 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2593 this.touchViewEl.addClass('in');
2596 this.doTouchViewQuery();
2600 hideTouchView : function()
2602 this.touchViewEl.removeClass('in');
2606 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2608 this.touchViewEl.setStyle('display', 'none');
2613 setTouchViewValue : function()
2620 Roo.each(this.tickItems, function(o){
2625 this.hideTouchView();
2628 doTouchViewQuery : function()
2637 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2641 if(!this.alwaysQuery || this.mode == 'local'){
2642 this.onTouchViewLoad();
2649 onTouchViewBeforeLoad : function(combo,opts)
2655 onTouchViewLoad : function()
2657 if(this.store.getCount() < 1){
2658 this.onTouchViewEmptyResults();
2662 this.clearTouchView();
2664 var rawValue = this.getRawValue();
2666 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2668 this.tickItems = [];
2670 this.store.data.each(function(d, rowIndex){
2671 var row = this.touchViewListGroup.createChild(template);
2673 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2674 row.addClass(d.data.cls);
2677 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2680 html : d.data[this.displayField]
2683 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2684 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2687 row.removeClass('selected');
2688 if(!this.multiple && this.valueField &&
2689 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2692 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2693 row.addClass('selected');
2696 if(this.multiple && this.valueField &&
2697 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2701 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2702 this.tickItems.push(d.data);
2705 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2709 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2711 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2713 if(this.modalTitle.length){
2714 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2717 var listHeight = this.touchViewListGroup.getHeight();
2721 if(firstChecked && listHeight > bodyHeight){
2722 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2727 onTouchViewLoadException : function()
2729 this.hideTouchView();
2732 onTouchViewEmptyResults : function()
2734 this.clearTouchView();
2736 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2738 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2742 clearTouchView : function()
2744 this.touchViewListGroup.dom.innerHTML = '';
2747 onTouchViewClick : function(e, el, o)
2752 var rowIndex = o.rowIndex;
2754 var r = this.store.getAt(rowIndex);
2756 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2759 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2760 c.dom.removeAttribute('checked');
2763 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2765 this.setFromData(r.data);
2767 var close = this.closeTriggerEl();
2773 this.hideTouchView();
2775 this.fireEvent('select', this, r, rowIndex);
2780 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2781 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2782 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2786 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2787 this.addItem(r.data);
2788 this.tickItems.push(r.data);
2792 getAutoCreateNativeIOS : function()
2795 cls: 'form-group' //input-group,
2800 cls : 'roo-ios-select'
2804 combobox.name = this.name;
2807 if (this.disabled) {
2808 combobox.disabled = true;
2811 var settings = this;
2813 ['xs','sm','md','lg'].map(function(size){
2814 if (settings[size]) {
2815 cfg.cls += ' col-' + size + '-' + settings[size];
2825 initIOSView : function()
2827 this.store.on('load', this.onIOSViewLoad, this);
2832 onIOSViewLoad : function()
2834 if(this.store.getCount() < 1){
2838 this.clearIOSView();
2840 if(this.allowBlank) {
2842 var default_text = '-- SELECT --';
2844 if(this.placeholder.length){
2845 default_text = this.placeholder;
2848 if(this.emptyTitle.length){
2849 default_text += ' - ' + this.emptyTitle + ' -';
2852 var opt = this.inputEl().createChild({
2859 o[this.valueField] = 0;
2860 o[this.displayField] = default_text;
2862 this.ios_options.push({
2869 this.store.data.each(function(d, rowIndex){
2873 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2874 html = d.data[this.displayField];
2879 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2880 value = d.data[this.valueField];
2889 if(this.value == d.data[this.valueField]){
2890 option['selected'] = true;
2893 var opt = this.inputEl().createChild(option);
2895 this.ios_options.push({
2902 this.inputEl().on('change', function(){
2903 this.fireEvent('select', this);
2908 clearIOSView: function()
2910 this.inputEl().dom.innerHTML = '';
2912 this.ios_options = [];
2915 setIOSValue: function(v)
2919 if(!this.ios_options){
2923 Roo.each(this.ios_options, function(opts){
2925 opts.el.dom.removeAttribute('selected');
2927 if(opts.data[this.valueField] != v){
2931 opts.el.dom.setAttribute('selected', true);
2937 * @cfg {Boolean} grow
2941 * @cfg {Number} growMin
2945 * @cfg {Number} growMax
2954 Roo.apply(Roo.bootstrap.ComboBox, {
2958 cls: 'modal-header',
2980 cls: 'list-group-item',
2984 cls: 'roo-combobox-list-group-item-value'
2988 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3002 listItemCheckbox : {
3004 cls: 'list-group-item',
3008 cls: 'roo-combobox-list-group-item-value'
3012 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3028 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3033 cls: 'modal-footer',
3041 cls: 'col-xs-6 text-left',
3044 cls: 'btn btn-danger roo-touch-view-cancel',
3050 cls: 'col-xs-6 text-right',
3053 cls: 'btn btn-success roo-touch-view-ok',
3064 Roo.apply(Roo.bootstrap.ComboBox, {
3066 touchViewTemplate : {
3068 cls: 'modal fade roo-combobox-touch-view',
3072 cls: 'modal-dialog',
3073 style : 'position:fixed', // we have to fix position....
3077 cls: 'modal-content',
3079 Roo.bootstrap.ComboBox.header,
3080 Roo.bootstrap.ComboBox.body,
3081 Roo.bootstrap.ComboBox.footer