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.store = Roo.factory(this.store, Roo.data);
651 this.store.parent = this;
653 // if we are building from html. then this element is so complex, that we can not really
654 // use the rendered HTML.
655 // so we have to trash and replace the previous code.
656 if (Roo.XComponent.build_from_html) {
657 // remove this element....
658 var e = this.el.dom, k=0;
659 while (e ) { e = e.previousSibling; ++k;}
664 this.rendered = false;
666 this.render(this.parent().getChildContainer(true), k);
669 if(Roo.isIOS && this.useNativeIOS){
678 if(Roo.isTouch && this.mobileTouchView){
679 this.initTouchView();
684 this.initTickableEvents();
688 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
692 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
694 this.hiddenField.dom.value =
695 this.hiddenValue !== undefined ? this.hiddenValue :
696 this.value !== undefined ? this.value : '';
698 // prevent input submission
699 this.el.dom.removeAttribute('name');
700 this.hiddenField.dom.setAttribute('name', this.hiddenName);
705 // this.el.dom.setAttribute('autocomplete', 'off');
708 var cls = 'x-combo-list';
710 //this.list = new Roo.Layer({
711 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
717 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
718 _this.list.setWidth(lw);
721 this.list.on('mouseover', this.onViewOver, this);
722 this.list.on('mousemove', this.onViewMove, this);
723 this.list.on('scroll', this.onViewScroll, this);
726 this.list.swallowEvent('mousewheel');
727 this.assetHeight = 0;
730 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
731 this.assetHeight += this.header.getHeight();
734 this.innerList = this.list.createChild({cls:cls+'-inner'});
735 this.innerList.on('mouseover', this.onViewOver, this);
736 this.innerList.on('mousemove', this.onViewMove, this);
737 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
739 if(this.allowBlank && !this.pageSize && !this.disableClear){
740 this.footer = this.list.createChild({cls:cls+'-ft'});
741 this.pageTb = new Roo.Toolbar(this.footer);
745 this.footer = this.list.createChild({cls:cls+'-ft'});
746 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
747 {pageSize: this.pageSize});
751 if (this.pageTb && this.allowBlank && !this.disableClear) {
753 this.pageTb.add(new Roo.Toolbar.Fill(), {
754 cls: 'x-btn-icon x-btn-clear',
760 _this.onSelect(false, -1);
765 this.assetHeight += this.footer.getHeight();
770 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
773 this.view = new Roo.View(this.list, this.tpl, {
774 singleSelect:true, store: this.store, selectedClass: this.selectedClass
776 //this.view.wrapEl.setDisplayed(false);
777 this.view.on('click', this.onViewClick, this);
780 this.store.on('beforeload', this.onBeforeLoad, this);
781 this.store.on('load', this.onLoad, this);
782 this.store.on('loadexception', this.onLoadException, this);
785 this.resizer = new Roo.Resizable(this.list, {
786 pinned:true, handles:'se'
788 this.resizer.on('resize', function(r, w, h){
789 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
791 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
792 this.restrictHeight();
794 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
798 this.editable = true;
799 this.setEditable(false);
804 if (typeof(this.events.add.listeners) != 'undefined') {
806 this.addicon = this.wrap.createChild(
807 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
809 this.addicon.on('click', function(e) {
810 this.fireEvent('add', this);
813 if (typeof(this.events.edit.listeners) != 'undefined') {
815 this.editicon = this.wrap.createChild(
816 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
818 this.editicon.setStyle('margin-left', '40px');
820 this.editicon.on('click', function(e) {
822 // we fire even if inothing is selected..
823 this.fireEvent('edit', this, this.lastData );
829 this.keyNav = new Roo.KeyNav(this.inputEl(), {
831 this.inKeyMode = true;
835 "down" : function(e){
836 if(!this.isExpanded()){
837 this.onTriggerClick();
839 this.inKeyMode = true;
844 "enter" : function(e){
845 // this.onViewClick();
849 if(this.fireEvent("specialkey", this, e)){
850 this.onViewClick(false);
863 if(this.fireEvent("specialkey", this, e)){
864 this.onViewClick(false);
872 doRelay : function(foo, bar, hname){
873 if(hname == 'down' || this.scope.isExpanded()){
874 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
883 this.queryDelay = Math.max(this.queryDelay || 10,
884 this.mode == 'local' ? 10 : 250);
887 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
890 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
892 if(this.editable !== false){
893 this.inputEl().on("keyup", this.onKeyUp, this);
895 if(this.forceSelection){
896 this.inputEl().on('blur', this.doForce, this);
900 this.choices = this.el.select('ul.roo-select2-choices', true).first();
901 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
905 initTickableEvents: function()
911 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
913 this.hiddenField.dom.value =
914 this.hiddenValue !== undefined ? this.hiddenValue :
915 this.value !== undefined ? this.value : '';
917 // prevent input submission
918 this.el.dom.removeAttribute('name');
919 this.hiddenField.dom.setAttribute('name', this.hiddenName);
924 // this.list = this.el.select('ul.dropdown-menu',true).first();
926 this.choices = this.el.select('ul.roo-select2-choices', true).first();
927 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
928 if(this.triggerList){
929 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
932 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
933 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
935 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
936 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
938 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
939 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
941 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
942 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
943 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
946 this.cancelBtn.hide();
951 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
952 _this.list.setWidth(lw);
955 this.list.on('mouseover', this.onViewOver, this);
956 this.list.on('mousemove', this.onViewMove, this);
958 this.list.on('scroll', this.onViewScroll, this);
961 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
964 this.view = new Roo.View(this.list, this.tpl, {
965 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
968 //this.view.wrapEl.setDisplayed(false);
969 this.view.on('click', this.onViewClick, this);
973 this.store.on('beforeload', this.onBeforeLoad, this);
974 this.store.on('load', this.onLoad, this);
975 this.store.on('loadexception', this.onLoadException, this);
978 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
980 this.inKeyMode = true;
984 "down" : function(e){
985 this.inKeyMode = true;
989 "enter" : function(e){
990 if(this.fireEvent("specialkey", this, e)){
991 this.onViewClick(false);
998 this.onTickableFooterButtonClick(e, false, false);
1001 "tab" : function(e){
1002 this.fireEvent("specialkey", this, e);
1004 this.onTickableFooterButtonClick(e, false, false);
1011 doRelay : function(e, fn, key){
1012 if(this.scope.isExpanded()){
1013 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1022 this.queryDelay = Math.max(this.queryDelay || 10,
1023 this.mode == 'local' ? 10 : 250);
1026 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1029 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1032 if(this.editable !== false){
1033 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1036 this.indicator = this.indicatorEl();
1039 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1040 this.indicator.hide();
1045 onDestroy : function(){
1047 this.view.setStore(null);
1048 this.view.el.removeAllListeners();
1049 this.view.el.remove();
1050 this.view.purgeListeners();
1053 this.list.dom.innerHTML = '';
1057 this.store.un('beforeload', this.onBeforeLoad, this);
1058 this.store.un('load', this.onLoad, this);
1059 this.store.un('loadexception', this.onLoadException, this);
1061 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1065 fireKey : function(e){
1066 if(e.isNavKeyPress() && !this.list.isVisible()){
1067 this.fireEvent("specialkey", this, e);
1072 onResize: function(w, h){
1073 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1075 // if(typeof w != 'number'){
1076 // // we do not handle it!?!?
1079 // var tw = this.trigger.getWidth();
1080 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1081 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1083 // this.inputEl().setWidth( this.adjustWidth('input', x));
1085 // //this.trigger.setStyle('left', x+'px');
1087 // if(this.list && this.listWidth === undefined){
1088 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1089 // this.list.setWidth(lw);
1090 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1098 * Allow or prevent the user from directly editing the field text. If false is passed,
1099 * the user will only be able to select from the items defined in the dropdown list. This method
1100 * is the runtime equivalent of setting the 'editable' config option at config time.
1101 * @param {Boolean} value True to allow the user to directly edit the field text
1103 setEditable : function(value){
1104 if(value == this.editable){
1107 this.editable = value;
1109 this.inputEl().dom.setAttribute('readOnly', true);
1110 this.inputEl().on('mousedown', this.onTriggerClick, this);
1111 this.inputEl().addClass('x-combo-noedit');
1113 this.inputEl().dom.setAttribute('readOnly', false);
1114 this.inputEl().un('mousedown', this.onTriggerClick, this);
1115 this.inputEl().removeClass('x-combo-noedit');
1121 onBeforeLoad : function(combo,opts){
1126 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1128 this.restrictHeight();
1129 this.selectedIndex = -1;
1133 onLoad : function(){
1135 this.hasQuery = false;
1141 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1142 this.loading.hide();
1145 if(this.store.getCount() > 0){
1148 this.restrictHeight();
1149 if(this.lastQuery == this.allQuery){
1150 if(this.editable && !this.tickable){
1151 this.inputEl().dom.select();
1155 !this.selectByValue(this.value, true) &&
1158 !this.store.lastOptions ||
1159 typeof(this.store.lastOptions.add) == 'undefined' ||
1160 this.store.lastOptions.add != true
1163 this.select(0, true);
1169 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1170 this.taTask.delay(this.typeAheadDelay);
1174 this.onEmptyResults();
1180 onLoadException : function()
1182 this.hasQuery = false;
1184 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1185 this.loading.hide();
1188 if(this.tickable && this.editable){
1193 // only causes errors at present
1194 //Roo.log(this.store.reader.jsonData);
1195 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1197 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1203 onTypeAhead : function(){
1204 if(this.store.getCount() > 0){
1205 var r = this.store.getAt(0);
1206 var newValue = r.data[this.displayField];
1207 var len = newValue.length;
1208 var selStart = this.getRawValue().length;
1210 if(selStart != len){
1211 this.setRawValue(newValue);
1212 this.selectText(selStart, newValue.length);
1218 onSelect : function(record, index){
1220 if(this.fireEvent('beforeselect', this, record, index) !== false){
1222 this.setFromData(index > -1 ? record.data : false);
1225 this.fireEvent('select', this, record, index);
1230 * Returns the currently selected field value or empty string if no value is set.
1231 * @return {String} value The selected value
1233 getValue : function()
1235 if(Roo.isIOS && this.useNativeIOS){
1236 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1240 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1243 if(this.valueField){
1244 return typeof this.value != 'undefined' ? this.value : '';
1246 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1250 getRawValue : function()
1252 if(Roo.isIOS && this.useNativeIOS){
1253 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1256 var v = this.inputEl().getValue();
1262 * Clears any text/value currently set in the field
1264 clearValue : function(){
1266 if(this.hiddenField){
1267 this.hiddenField.dom.value = '';
1270 this.setRawValue('');
1271 this.lastSelectionText = '';
1272 this.lastData = false;
1274 var close = this.closeTriggerEl();
1285 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1286 * will be displayed in the field. If the value does not match the data value of an existing item,
1287 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1288 * Otherwise the field will be blank (although the value will still be set).
1289 * @param {String} value The value to match
1291 setValue : function(v)
1293 if(Roo.isIOS && this.useNativeIOS){
1294 this.setIOSValue(v);
1304 if(this.valueField){
1305 var r = this.findRecord(this.valueField, v);
1307 text = r.data[this.displayField];
1308 }else if(this.valueNotFoundText !== undefined){
1309 text = this.valueNotFoundText;
1312 this.lastSelectionText = text;
1313 if(this.hiddenField){
1314 this.hiddenField.dom.value = v;
1316 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1319 var close = this.closeTriggerEl();
1322 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1328 * @property {Object} the last set data for the element
1333 * Sets the value of the field based on a object which is related to the record format for the store.
1334 * @param {Object} value the value to set as. or false on reset?
1336 setFromData : function(o){
1343 var dv = ''; // display value
1344 var vv = ''; // value value..
1346 if (this.displayField) {
1347 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1349 // this is an error condition!!!
1350 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1353 if(this.valueField){
1354 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1357 var close = this.closeTriggerEl();
1360 if(dv.length || vv * 1 > 0){
1362 this.blockFocus=true;
1368 if(this.hiddenField){
1369 this.hiddenField.dom.value = vv;
1371 this.lastSelectionText = dv;
1372 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1376 // no hidden field.. - we store the value in 'value', but still display
1377 // display field!!!!
1378 this.lastSelectionText = dv;
1379 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1387 // overridden so that last data is reset..
1394 this.setValue(this.originalValue);
1395 //this.clearInvalid();
1396 this.lastData = false;
1398 this.view.clearSelections();
1404 findRecord : function(prop, value){
1406 if(this.store.getCount() > 0){
1407 this.store.each(function(r){
1408 if(r.data[prop] == value){
1420 // returns hidden if it's set..
1421 if (!this.rendered) {return ''};
1422 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1426 onViewMove : function(e, t){
1427 this.inKeyMode = false;
1431 onViewOver : function(e, t){
1432 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1435 var item = this.view.findItemFromChild(t);
1438 var index = this.view.indexOf(item);
1439 this.select(index, false);
1444 onViewClick : function(view, doFocus, el, e)
1446 var index = this.view.getSelectedIndexes()[0];
1448 var r = this.store.getAt(index);
1452 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1459 Roo.each(this.tickItems, function(v,k){
1461 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1463 _this.tickItems.splice(k, 1);
1465 if(typeof(e) == 'undefined' && view == false){
1466 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1478 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1479 this.tickItems.push(r.data);
1482 if(typeof(e) == 'undefined' && view == false){
1483 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1490 this.onSelect(r, index);
1492 if(doFocus !== false && !this.blockFocus){
1493 this.inputEl().focus();
1498 restrictHeight : function(){
1499 //this.innerList.dom.style.height = '';
1500 //var inner = this.innerList.dom;
1501 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1502 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1503 //this.list.beginUpdate();
1504 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1505 this.list.alignTo(this.inputEl(), this.listAlign);
1506 this.list.alignTo(this.inputEl(), this.listAlign);
1507 //this.list.endUpdate();
1511 onEmptyResults : function(){
1513 if(this.tickable && this.editable){
1514 this.restrictHeight();
1522 * Returns true if the dropdown list is expanded, else false.
1524 isExpanded : function(){
1525 return this.list.isVisible();
1529 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1530 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1531 * @param {String} value The data value of the item to select
1532 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1533 * selected item if it is not currently in view (defaults to true)
1534 * @return {Boolean} True if the value matched an item in the list, else false
1536 selectByValue : function(v, scrollIntoView){
1537 if(v !== undefined && v !== null){
1538 var r = this.findRecord(this.valueField || this.displayField, v);
1540 this.select(this.store.indexOf(r), scrollIntoView);
1548 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1549 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1550 * @param {Number} index The zero-based index of the list item to select
1551 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1552 * selected item if it is not currently in view (defaults to true)
1554 select : function(index, scrollIntoView){
1555 this.selectedIndex = index;
1556 this.view.select(index);
1557 if(scrollIntoView !== false){
1558 var el = this.view.getNode(index);
1560 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1563 this.list.scrollChildIntoView(el, false);
1569 selectNext : function(){
1570 var ct = this.store.getCount();
1572 if(this.selectedIndex == -1){
1574 }else if(this.selectedIndex < ct-1){
1575 this.select(this.selectedIndex+1);
1581 selectPrev : function(){
1582 var ct = this.store.getCount();
1584 if(this.selectedIndex == -1){
1586 }else if(this.selectedIndex != 0){
1587 this.select(this.selectedIndex-1);
1593 onKeyUp : function(e){
1594 if(this.editable !== false && !e.isSpecialKey()){
1595 this.lastKey = e.getKey();
1596 this.dqTask.delay(this.queryDelay);
1601 validateBlur : function(){
1602 return !this.list || !this.list.isVisible();
1606 initQuery : function(){
1608 var v = this.getRawValue();
1610 if(this.tickable && this.editable){
1611 v = this.tickableInputEl().getValue();
1618 doForce : function(){
1619 if(this.inputEl().dom.value.length > 0){
1620 this.inputEl().dom.value =
1621 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1627 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1628 * query allowing the query action to be canceled if needed.
1629 * @param {String} query The SQL query to execute
1630 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1631 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1632 * saved in the current store (defaults to false)
1634 doQuery : function(q, forceAll){
1636 if(q === undefined || q === null){
1645 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1650 forceAll = qe.forceAll;
1651 if(forceAll === true || (q.length >= this.minChars)){
1653 this.hasQuery = true;
1655 if(this.lastQuery != q || this.alwaysQuery){
1657 if(this.mode == 'local'){
1658 this.selectedIndex = -1;
1660 this.store.clearFilter();
1663 if(this.specialFilter){
1664 this.fireEvent('specialfilter', this);
1669 this.store.filter(this.displayField, q);
1672 this.store.fireEvent("datachanged", this.store);
1679 this.store.baseParams[this.queryParam] = q;
1681 var options = {params : this.getParams(q)};
1685 options.params.start = this.page * this.pageSize;
1688 this.store.load(options);
1691 * this code will make the page width larger, at the beginning, the list not align correctly,
1692 * we should expand the list on onLoad
1698 this.selectedIndex = -1;
1703 this.loadNext = false;
1707 getParams : function(q){
1709 //p[this.queryParam] = q;
1713 p.limit = this.pageSize;
1719 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1721 collapse : function(){
1722 if(!this.isExpanded()){
1728 this.hasFocus = false;
1732 this.cancelBtn.hide();
1733 this.trigger.show();
1736 this.tickableInputEl().dom.value = '';
1737 this.tickableInputEl().blur();
1742 Roo.get(document).un('mousedown', this.collapseIf, this);
1743 Roo.get(document).un('mousewheel', this.collapseIf, this);
1744 if (!this.editable) {
1745 Roo.get(document).un('keydown', this.listKeyPress, this);
1747 this.fireEvent('collapse', this);
1753 collapseIf : function(e){
1754 var in_combo = e.within(this.el);
1755 var in_list = e.within(this.list);
1756 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1758 if (in_combo || in_list || is_list) {
1759 //e.stopPropagation();
1764 this.onTickableFooterButtonClick(e, false, false);
1772 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1774 expand : function(){
1776 if(this.isExpanded() || !this.hasFocus){
1780 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1781 this.list.setWidth(lw);
1787 this.restrictHeight();
1791 this.tickItems = Roo.apply([], this.item);
1794 this.cancelBtn.show();
1795 this.trigger.hide();
1798 this.tickableInputEl().focus();
1803 Roo.get(document).on('mousedown', this.collapseIf, this);
1804 Roo.get(document).on('mousewheel', this.collapseIf, this);
1805 if (!this.editable) {
1806 Roo.get(document).on('keydown', this.listKeyPress, this);
1809 this.fireEvent('expand', this);
1813 // Implements the default empty TriggerField.onTriggerClick function
1814 onTriggerClick : function(e)
1816 Roo.log('trigger click');
1818 if(this.disabled || !this.triggerList){
1823 this.loadNext = false;
1825 if(this.isExpanded()){
1827 if (!this.blockFocus) {
1828 this.inputEl().focus();
1832 this.hasFocus = true;
1833 if(this.triggerAction == 'all') {
1834 this.doQuery(this.allQuery, true);
1836 this.doQuery(this.getRawValue());
1838 if (!this.blockFocus) {
1839 this.inputEl().focus();
1844 onTickableTriggerClick : function(e)
1851 this.loadNext = false;
1852 this.hasFocus = true;
1854 if(this.triggerAction == 'all') {
1855 this.doQuery(this.allQuery, true);
1857 this.doQuery(this.getRawValue());
1861 onSearchFieldClick : function(e)
1863 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1864 this.onTickableFooterButtonClick(e, false, false);
1868 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1873 this.loadNext = false;
1874 this.hasFocus = true;
1876 if(this.triggerAction == 'all') {
1877 this.doQuery(this.allQuery, true);
1879 this.doQuery(this.getRawValue());
1883 listKeyPress : function(e)
1885 //Roo.log('listkeypress');
1886 // scroll to first matching element based on key pres..
1887 if (e.isSpecialKey()) {
1890 var k = String.fromCharCode(e.getKey()).toUpperCase();
1893 var csel = this.view.getSelectedNodes();
1894 var cselitem = false;
1896 var ix = this.view.indexOf(csel[0]);
1897 cselitem = this.store.getAt(ix);
1898 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1904 this.store.each(function(v) {
1906 // start at existing selection.
1907 if (cselitem.id == v.id) {
1913 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1914 match = this.store.indexOf(v);
1920 if (match === false) {
1921 return true; // no more action?
1924 this.view.select(match);
1925 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1926 sn.scrollIntoView(sn.dom.parentNode, false);
1929 onViewScroll : function(e, t){
1931 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){
1935 this.hasQuery = true;
1937 this.loading = this.list.select('.loading', true).first();
1939 if(this.loading === null){
1940 this.list.createChild({
1942 cls: 'loading roo-select2-more-results roo-select2-active',
1943 html: 'Loading more results...'
1946 this.loading = this.list.select('.loading', true).first();
1948 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1950 this.loading.hide();
1953 this.loading.show();
1958 this.loadNext = true;
1960 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1965 addItem : function(o)
1967 var dv = ''; // display value
1969 if (this.displayField) {
1970 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1972 // this is an error condition!!!
1973 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1980 var choice = this.choices.createChild({
1982 cls: 'roo-select2-search-choice',
1991 cls: 'roo-select2-search-choice-close fa fa-times',
1996 }, this.searchField);
1998 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2000 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2008 this.inputEl().dom.value = '';
2013 onRemoveItem : function(e, _self, o)
2017 this.lastItem = Roo.apply([], this.item);
2019 var index = this.item.indexOf(o.data) * 1;
2022 Roo.log('not this item?!');
2026 this.item.splice(index, 1);
2031 this.fireEvent('remove', this, e);
2037 syncValue : function()
2039 if(!this.item.length){
2046 Roo.each(this.item, function(i){
2047 if(_this.valueField){
2048 value.push(i[_this.valueField]);
2055 this.value = value.join(',');
2057 if(this.hiddenField){
2058 this.hiddenField.dom.value = this.value;
2061 this.store.fireEvent("datachanged", this.store);
2066 clearItem : function()
2074 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2082 if(this.tickable && !Roo.isTouch){
2083 this.view.refresh();
2087 inputEl: function ()
2089 if(Roo.isIOS && this.useNativeIOS){
2090 return this.el.select('select.roo-ios-select', true).first();
2093 if(Roo.isTouch && this.mobileTouchView){
2094 return this.el.select('input.form-control',true).first();
2098 return this.searchField;
2101 return this.el.select('input.form-control',true).first();
2104 onTickableFooterButtonClick : function(e, btn, el)
2108 this.lastItem = Roo.apply([], this.item);
2110 if(btn && btn.name == 'cancel'){
2111 this.tickItems = Roo.apply([], this.item);
2120 Roo.each(this.tickItems, function(o){
2128 validate : function()
2130 var v = this.getRawValue();
2133 v = this.getValue();
2136 if(this.disabled || this.allowBlank || v.length){
2145 tickableInputEl : function()
2147 if(!this.tickable || !this.editable){
2148 return this.inputEl();
2151 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2155 getAutoCreateTouchView : function()
2160 cls: 'form-group' //input-group
2166 type : this.inputType,
2167 cls : 'form-control x-combo-noedit',
2168 autocomplete: 'new-password',
2169 placeholder : this.placeholder || '',
2174 input.name = this.name;
2178 input.cls += ' input-' + this.size;
2181 if (this.disabled) {
2182 input.disabled = true;
2193 inputblock.cls += ' input-group';
2195 inputblock.cn.unshift({
2197 cls : 'input-group-addon',
2202 if(this.removable && !this.multiple){
2203 inputblock.cls += ' roo-removable';
2205 inputblock.cn.push({
2208 cls : 'roo-combo-removable-btn close'
2212 if(this.hasFeedback && !this.allowBlank){
2214 inputblock.cls += ' has-feedback';
2216 inputblock.cn.push({
2218 cls: 'glyphicon form-control-feedback'
2225 inputblock.cls += (this.before) ? '' : ' input-group';
2227 inputblock.cn.push({
2229 cls : 'input-group-addon',
2240 cls: 'form-hidden-field'
2254 cls: 'form-hidden-field'
2258 cls: 'roo-select2-choices',
2262 cls: 'roo-select2-search-field',
2275 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2281 if(!this.multiple && this.showToggleBtn){
2288 if (this.caret != false) {
2291 cls: 'fa fa-' + this.caret
2298 cls : 'input-group-addon btn dropdown-toggle',
2303 cls: 'combobox-clear',
2317 combobox.cls += ' roo-select2-container-multi';
2320 var align = this.labelAlign || this.parentLabelAlign();
2322 if (align ==='left' && this.fieldLabel.length) {
2327 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2328 tooltip : 'This field is required'
2332 cls : 'control-label',
2333 html : this.fieldLabel
2344 var labelCfg = cfg.cn[1];
2345 var contentCfg = cfg.cn[2];
2348 if(this.indicatorpos == 'right'){
2352 cls : 'control-label',
2353 html : this.fieldLabel,
2357 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2358 tooltip : 'This field is required'
2369 labelCfg = cfg.cn[0];
2370 contentCfg = cfg.cn[1];
2375 if(this.labelWidth > 12){
2376 labelCfg.style = "width: " + this.labelWidth + 'px';
2379 if(this.labelWidth < 13 && this.labelmd == 0){
2380 this.labelmd = this.labelWidth;
2383 if(this.labellg > 0){
2384 labelCfg.cls += ' col-lg-' + this.labellg;
2385 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2388 if(this.labelmd > 0){
2389 labelCfg.cls += ' col-md-' + this.labelmd;
2390 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2393 if(this.labelsm > 0){
2394 labelCfg.cls += ' col-sm-' + this.labelsm;
2395 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2398 if(this.labelxs > 0){
2399 labelCfg.cls += ' col-xs-' + this.labelxs;
2400 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2404 } else if ( this.fieldLabel.length) {
2408 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2409 tooltip : 'This field is required'
2413 cls : 'control-label',
2414 html : this.fieldLabel
2425 if(this.indicatorpos == 'right'){
2429 cls : 'control-label',
2430 html : this.fieldLabel,
2434 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2435 tooltip : 'This field is required'
2452 var settings = this;
2454 ['xs','sm','md','lg'].map(function(size){
2455 if (settings[size]) {
2456 cfg.cls += ' col-' + size + '-' + settings[size];
2463 initTouchView : function()
2465 this.renderTouchView();
2467 this.touchViewEl.on('scroll', function(){
2468 this.el.dom.scrollTop = 0;
2471 this.originalValue = this.getValue();
2473 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2475 this.inputEl().on("click", this.showTouchView, this);
2476 if (this.triggerEl) {
2477 this.triggerEl.on("click", this.showTouchView, this);
2481 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2482 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2484 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2486 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2487 this.store.on('load', this.onTouchViewLoad, this);
2488 this.store.on('loadexception', this.onTouchViewLoadException, this);
2490 if(this.hiddenName){
2492 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2494 this.hiddenField.dom.value =
2495 this.hiddenValue !== undefined ? this.hiddenValue :
2496 this.value !== undefined ? this.value : '';
2498 this.el.dom.removeAttribute('name');
2499 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2503 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2504 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2507 if(this.removable && !this.multiple){
2508 var close = this.closeTriggerEl();
2510 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2511 close.on('click', this.removeBtnClick, this, close);
2515 * fix the bug in Safari iOS8
2517 this.inputEl().on("focus", function(e){
2518 document.activeElement.blur();
2526 renderTouchView : function()
2528 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2529 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2531 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2532 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2534 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2535 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2536 this.touchViewBodyEl.setStyle('overflow', 'auto');
2538 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2539 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2541 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2542 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2546 showTouchView : function()
2552 this.touchViewHeaderEl.hide();
2554 if(this.modalTitle.length){
2555 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2556 this.touchViewHeaderEl.show();
2559 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2560 this.touchViewEl.show();
2562 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2564 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2565 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2567 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2569 if(this.modalTitle.length){
2570 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2573 this.touchViewBodyEl.setHeight(bodyHeight);
2577 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2579 this.touchViewEl.addClass('in');
2582 this.doTouchViewQuery();
2586 hideTouchView : function()
2588 this.touchViewEl.removeClass('in');
2592 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2594 this.touchViewEl.setStyle('display', 'none');
2599 setTouchViewValue : function()
2606 Roo.each(this.tickItems, function(o){
2611 this.hideTouchView();
2614 doTouchViewQuery : function()
2623 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2627 if(!this.alwaysQuery || this.mode == 'local'){
2628 this.onTouchViewLoad();
2635 onTouchViewBeforeLoad : function(combo,opts)
2641 onTouchViewLoad : function()
2643 if(this.store.getCount() < 1){
2644 this.onTouchViewEmptyResults();
2648 this.clearTouchView();
2650 var rawValue = this.getRawValue();
2652 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2654 this.tickItems = [];
2656 this.store.data.each(function(d, rowIndex){
2657 var row = this.touchViewListGroup.createChild(template);
2659 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2660 row.addClass(d.data.cls);
2663 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2666 html : d.data[this.displayField]
2669 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2670 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2673 row.removeClass('selected');
2674 if(!this.multiple && this.valueField &&
2675 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2678 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2679 row.addClass('selected');
2682 if(this.multiple && this.valueField &&
2683 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2687 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2688 this.tickItems.push(d.data);
2691 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2695 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2697 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2699 if(this.modalTitle.length){
2700 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2703 var listHeight = this.touchViewListGroup.getHeight();
2707 if(firstChecked && listHeight > bodyHeight){
2708 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2713 onTouchViewLoadException : function()
2715 this.hideTouchView();
2718 onTouchViewEmptyResults : function()
2720 this.clearTouchView();
2722 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2724 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2728 clearTouchView : function()
2730 this.touchViewListGroup.dom.innerHTML = '';
2733 onTouchViewClick : function(e, el, o)
2738 var rowIndex = o.rowIndex;
2740 var r = this.store.getAt(rowIndex);
2742 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2745 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2746 c.dom.removeAttribute('checked');
2749 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2751 this.setFromData(r.data);
2753 var close = this.closeTriggerEl();
2759 this.hideTouchView();
2761 this.fireEvent('select', this, r, rowIndex);
2766 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2767 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2768 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2772 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2773 this.addItem(r.data);
2774 this.tickItems.push(r.data);
2778 getAutoCreateNativeIOS : function()
2781 cls: 'form-group' //input-group,
2786 cls : 'roo-ios-select'
2790 combobox.name = this.name;
2793 if (this.disabled) {
2794 combobox.disabled = true;
2797 var settings = this;
2799 ['xs','sm','md','lg'].map(function(size){
2800 if (settings[size]) {
2801 cfg.cls += ' col-' + size + '-' + settings[size];
2811 initIOSView : function()
2813 this.store.on('load', this.onIOSViewLoad, this);
2818 onIOSViewLoad : function()
2820 if(this.store.getCount() < 1){
2824 this.clearIOSView();
2826 if(this.allowBlank) {
2828 var default_text = '-- SELECT --';
2830 var opt = this.inputEl().createChild({
2837 o[this.valueField] = 0;
2838 o[this.displayField] = default_text;
2840 this.ios_options.push({
2847 this.store.data.each(function(d, rowIndex){
2851 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2852 html = d.data[this.displayField];
2857 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2858 value = d.data[this.valueField];
2867 if(this.value == d.data[this.valueField]){
2868 option['selected'] = true;
2871 var opt = this.inputEl().createChild(option);
2873 this.ios_options.push({
2880 this.inputEl().on('change', function(){
2881 this.fireEvent('select', this);
2886 clearIOSView: function()
2888 this.inputEl().dom.innerHTML = '';
2890 this.ios_options = [];
2893 setIOSValue: function(v)
2897 if(!this.ios_options){
2901 Roo.each(this.ios_options, function(opts){
2903 opts.el.dom.removeAttribute('selected');
2905 if(opts.data[this.valueField] != v){
2909 opts.el.dom.setAttribute('selected', true);
2915 * @cfg {Boolean} grow
2919 * @cfg {Number} growMin
2923 * @cfg {Number} growMax
2932 Roo.apply(Roo.bootstrap.ComboBox, {
2936 cls: 'modal-header',
2958 cls: 'list-group-item',
2962 cls: 'roo-combobox-list-group-item-value'
2966 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2980 listItemCheckbox : {
2982 cls: 'list-group-item',
2986 cls: 'roo-combobox-list-group-item-value'
2990 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3006 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3011 cls: 'modal-footer',
3019 cls: 'col-xs-6 text-left',
3022 cls: 'btn btn-danger roo-touch-view-cancel',
3028 cls: 'col-xs-6 text-right',
3031 cls: 'btn btn-success roo-touch-view-ok',
3042 Roo.apply(Roo.bootstrap.ComboBox, {
3044 touchViewTemplate : {
3046 cls: 'modal fade roo-combobox-touch-view',
3050 cls: 'modal-dialog',
3051 style : 'position:fixed', // we have to fix position....
3055 cls: 'modal-content',
3057 Roo.bootstrap.ComboBox.header,
3058 Roo.bootstrap.ComboBox.body,
3059 Roo.bootstrap.ComboBox.footer