7 * @class Roo.bootstrap.form.ComboBox
8 * @extends Roo.bootstrap.form.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 ''
20 * @cfg {Number} width fixed with? experimental
22 * Create a new ComboBox.
23 * @param {Object} config Configuration options
25 Roo.bootstrap.form.ComboBox = function(config){
26 Roo.bootstrap.form.ComboBox.superclass.constructor.call(this, config);
30 * Fires when the dropdown list is expanded
31 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
36 * Fires when the dropdown list is collapsed
37 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
42 * Fires before a list item is selected. Return false to cancel the selection.
43 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
44 * @param {Roo.data.Record} record The data record returned from the underlying store
45 * @param {Number} index The index of the selected item in the dropdown list
47 'beforeselect' : true,
50 * Fires when a list item is selected
51 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
52 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
53 * @param {Number} index The index of the selected item in the dropdown list
58 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
59 * The event object passed has these properties:
60 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
61 * @param {String} query The query
62 * @param {Boolean} forceAll true to force "all" query
63 * @param {Boolean} cancel true to cancel the query
64 * @param {Object} e The query event object
69 * Fires when the 'add' icon is pressed (add a listener to enable add button)
70 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
75 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
76 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
77 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
82 * Fires when the remove value from the combobox array
83 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
88 * Fires when the remove value from the combobox array
89 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
93 * @event specialfilter
94 * Fires when specialfilter
95 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
97 'specialfilter' : true,
100 * Fires when tick the element
101 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
105 * @event touchviewdisplay
106 * Fires when touch view require special display (default is using displayField)
107 * @param {Roo.bootstrap.form.ComboBox} combo This combo box
108 * @param {Object} cfg set html .
110 'touchviewdisplay' : true
117 this.selectedIndex = -1;
118 if(this.mode == 'local'){
119 if(config.queryDelay === undefined){
120 this.queryDelay = 10;
122 if(config.minChars === undefined){
128 Roo.extend(Roo.bootstrap.form.ComboBox, Roo.bootstrap.form.TriggerField, {
131 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
132 * rendering into an Roo.Editor, defaults to false)
135 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
136 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
139 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
142 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
143 * the dropdown list (defaults to undefined, with no header element)
147 * @cfg {String/Roo.Template} tpl The template to use to render the output default is '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>'
151 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
153 listWidth: undefined,
155 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
156 * mode = 'remote' or 'text' if mode = 'local')
158 displayField: undefined,
161 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
162 * mode = 'remote' or 'value' if mode = 'local').
163 * Note: use of a valueField requires the user make a selection
164 * in order for a value to be mapped.
166 valueField: undefined,
168 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
173 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
174 * field's data value (defaults to the underlying DOM element's name)
176 hiddenName: undefined,
178 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
182 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
184 selectedClass: 'active',
187 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
191 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
192 * anchor positions (defaults to 'tl-bl')
196 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
198 // maxHeight: 300, // not used (change maxHeight in CSS. target the list using listClass)
200 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
201 * query specified by the allQuery config option (defaults to 'query')
203 triggerAction: 'query',
205 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
206 * (defaults to 4, does not apply if editable = false)
210 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
211 * delay (typeAheadDelay) if it matches a known value (defaults to false)
215 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
216 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
220 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
221 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
225 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
226 * when editable = true (defaults to false)
230 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
234 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
235 * when mode = 'remote' (defaults to 'Loading...')
237 loadingText: 'Loading...',
239 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
243 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
247 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
248 * traditional select (defaults to true)
252 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
256 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
260 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
261 * listWidth has a higher value)
265 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
266 * allow the user to set arbitrary text into the field (defaults to false)
268 forceSelection:false,
270 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
271 * if typeAhead = true (defaults to 250)
273 typeAheadDelay : 250,
275 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
276 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
278 valueNotFoundText : undefined,
280 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
285 * @cfg {Boolean} disableClear Disable showing of clear button.
287 disableClear : false,
289 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
294 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
299 * @cfg {String} invalidClass DEPRICATED - uses BS4 is-valid now
301 invalidClass : "has-warning",
304 * @cfg {String} validClass DEPRICATED - uses BS4 is-valid now
306 validClass : "has-success",
309 * @cfg {Boolean} specialFilter (true|false) special filter default false
311 specialFilter : false,
314 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
316 mobileTouchView : true,
319 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
321 useNativeIOS : false,
324 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
326 mobile_restrict_height : false,
340 btnPosition : 'right',
342 showToggleBtn : true,
344 emptyResultText: 'Empty',
345 triggerText : 'Select',
349 // element that contains real text value.. (when hidden is used..)
351 getAutoCreate : function()
356 * Render classic select for iso
359 if(Roo.isIOS && this.useNativeIOS){
360 cfg = this.getAutoCreateNativeIOS();
368 if(Roo.isTouch && this.mobileTouchView){
369 cfg = this.getAutoCreateTouchView();
377 cfg = Roo.bootstrap.form.ComboBox.superclass.getAutoCreate.call(this);
382 * ComboBox with tickable selections
385 var align = this.labelAlign || this.parentLabelAlign();
388 cls : 'form-group roo-combobox-tickable' //input-group
391 var btn_text_select = '';
392 var btn_text_done = '';
393 var btn_text_cancel = '';
395 if (this.btn_text_show) {
396 btn_text_select = 'Select';
397 btn_text_done = 'Done';
398 btn_text_cancel = 'Cancel';
403 cls : 'tickable-buttons',
408 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
409 //html : this.triggerText
410 html: btn_text_select
416 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
424 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
426 html: btn_text_cancel
434 cls: 'roo-select2-search-field-input'
440 Roo.each(buttons.cn, function(c){
442 c.cls += ' btn-' + _this.size;
445 if (_this.disabled) {
452 style : 'display: contents',
457 cls: 'form-hidden-field'
461 cls: 'roo-select2-choices',
465 cls: 'roo-select2-search-field',
476 cls: 'roo-select2-container input-group roo-select2-container-multi',
482 // cls: 'typeahead typeahead-long dropdown-menu',
483 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
488 if(this.hasFeedback && !this.allowBlank){
492 cls: 'glyphicon form-control-feedback'
495 combobox.cn.push(feedback);
502 cls : 'roo-required-indicator ' + (this.indicatorpos == 'right' ? 'right' : 'left') +'-indicator text-danger fa fa-lg fa-star',
503 tooltip : 'This field is required'
506 if (this.allowBlank) {
509 style : 'display:none'
512 if (align ==='left' && this.fieldLabel.length) {
514 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
521 cls : 'control-label col-form-label',
522 html : this.fieldLabel
534 var labelCfg = cfg.cn[1];
535 var contentCfg = cfg.cn[2];
538 if(this.indicatorpos == 'right'){
544 cls : 'control-label col-form-label',
548 html : this.fieldLabel
564 labelCfg = cfg.cn[0];
565 contentCfg = cfg.cn[1];
569 if(this.labelWidth > 12){
570 labelCfg.style = "width: " + this.labelWidth + 'px';
572 if(this.width * 1 > 0){
573 contentCfg.style = "width: " + this.width + 'px';
575 if(this.labelWidth < 13 && this.labelmd == 0){
576 this.labelmd = this.labelWidth;
579 if(this.labellg > 0){
580 labelCfg.cls += ' col-lg-' + this.labellg;
581 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
584 if(this.labelmd > 0){
585 labelCfg.cls += ' col-md-' + this.labelmd;
586 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
589 if(this.labelsm > 0){
590 labelCfg.cls += ' col-sm-' + this.labelsm;
591 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
594 if(this.labelxs > 0){
595 labelCfg.cls += ' col-xs-' + this.labelxs;
596 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
600 } else if ( this.fieldLabel.length) {
601 // Roo.log(" label");
606 //cls : 'input-group-addon',
607 html : this.fieldLabel
612 if(this.indicatorpos == 'right'){
616 //cls : 'input-group-addon',
617 html : this.fieldLabel
627 // Roo.log(" no label && no align");
634 ['xs','sm','md','lg'].map(function(size){
635 if (settings[size]) {
636 cfg.cls += ' col-' + size + '-' + settings[size];
644 _initEventsCalled : false,
647 initEvents: function()
649 if (this._initEventsCalled) { // as we call render... prevent looping...
652 this._initEventsCalled = true;
655 throw "can not find store for combo";
658 this.indicator = this.indicatorEl();
660 this.store = Roo.factory(this.store, Roo.data);
661 this.store.parent = this;
663 // if we are building from html. then this element is so complex, that we can not really
664 // use the rendered HTML.
665 // so we have to trash and replace the previous code.
666 if (Roo.XComponent.build_from_html) {
667 // remove this element....
668 var e = this.el.dom, k=0;
669 while (e ) { e = e.previousSibling; ++k;}
674 this.rendered = false;
676 this.render(this.parent().getChildContainer(true), k);
679 if(Roo.isIOS && this.useNativeIOS){
688 if(Roo.isTouch && this.mobileTouchView){
689 this.initTouchView();
694 this.initTickableEvents();
698 Roo.bootstrap.form.ComboBox.superclass.initEvents.call(this);
702 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
704 this.hiddenField.dom.value =
705 this.hiddenValue !== undefined ? this.hiddenValue :
706 this.value !== undefined ? this.value : '';
708 // prevent input submission
709 this.el.dom.removeAttribute('name');
710 this.hiddenField.dom.setAttribute('name', this.hiddenName);
715 // this.el.dom.setAttribute('autocomplete', 'off');
718 var cls = 'x-combo-list';
720 //this.list = new Roo.Layer({
721 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
724 this.list.addClass(this.listClass);
729 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
730 _this.list.setWidth(lw);
733 this.list.on('mouseover', this.onViewOver, this);
734 this.list.on('mousemove', this.onViewMove, this);
735 this.list.on('scroll', this.onViewScroll, this);
738 this.list.swallowEvent('mousewheel');
739 this.assetHeight = 0;
742 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
743 this.assetHeight += this.header.getHeight();
746 this.innerList = this.list.createChild({cls:cls+'-inner'});
747 this.innerList.on('mouseover', this.onViewOver, this);
748 this.innerList.on('mousemove', this.onViewMove, this);
749 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
751 if(this.allowBlank && !this.pageSize && !this.disableClear){
752 this.footer = this.list.createChild({cls:cls+'-ft'});
753 this.pageTb = new Roo.Toolbar(this.footer);
757 this.footer = this.list.createChild({cls:cls+'-ft'});
758 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
759 {pageSize: this.pageSize});
763 if (this.pageTb && this.allowBlank && !this.disableClear) {
765 this.pageTb.add(new Roo.Toolbar.Fill(), {
766 cls: 'x-btn-icon x-btn-clear',
772 _this.onSelect(false, -1);
777 this.assetHeight += this.footer.getHeight();
782 this.tpl = Roo.bootstrap.version == 4 ?
783 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
784 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
787 this.view = new Roo.View(this.list, this.tpl, {
788 singleSelect:true, store: this.store, selectedClass: this.selectedClass
790 //this.view.wrapEl.setDisplayed(false);
791 this.view.on('click', this.onViewClick, this);
794 this.store.on('beforeload', this.onBeforeLoad, this);
795 this.store.on('load', this.onLoad, this);
796 this.store.on('loadexception', this.onLoadException, this);
799 this.resizer = new Roo.Resizable(this.list, {
800 pinned:true, handles:'se'
802 this.resizer.on('resize', function(r, w, h){
803 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
805 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
806 this.restrictHeight();
808 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
812 this.editable = true;
813 this.setEditable(false);
818 if (typeof(this.events.add.listeners) != 'undefined') {
820 this.addicon = this.wrap.createChild(
821 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
823 this.addicon.on('click', function(e) {
824 this.fireEvent('add', this);
827 if (typeof(this.events.edit.listeners) != 'undefined') {
829 this.editicon = this.wrap.createChild(
830 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
832 this.editicon.setStyle('margin-left', '40px');
834 this.editicon.on('click', function(e) {
836 // we fire even if inothing is selected..
837 this.fireEvent('edit', this, this.lastData );
843 this.keyNav = new Roo.KeyNav(this.inputEl(), {
845 this.inKeyMode = true;
849 "down" : function(e){
850 if(!this.isExpanded()){
851 this.onTriggerClick();
853 this.inKeyMode = true;
858 "enter" : function(e){
859 // this.onViewClick();
863 if(this.fireEvent("specialkey", this, e)){
864 this.onViewClick(false);
877 if(this.fireEvent("specialkey", this, e)){
878 this.onViewClick(false);
886 doRelay : function(foo, bar, hname){
887 if(hname == 'down' || this.scope.isExpanded()){
888 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
897 this.queryDelay = Math.max(this.queryDelay || 10,
898 this.mode == 'local' ? 10 : 250);
901 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
904 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
906 if(this.editable !== false){
907 this.inputEl().on("keyup", this.onKeyUp, this);
909 if(this.forceSelection){
910 this.inputEl().on('blur', this.doForce, this);
914 this.choices = this.el.select('ul.roo-select2-choices', true).first();
915 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
919 initTickableEvents: function()
925 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
927 this.hiddenField.dom.value =
928 this.hiddenValue !== undefined ? this.hiddenValue :
929 this.value !== undefined ? this.value : '';
931 // prevent input submission
932 this.el.dom.removeAttribute('name');
933 this.hiddenField.dom.setAttribute('name', this.hiddenName);
938 // this.list = this.el.select('ul.dropdown-menu',true).first();
940 this.choices = this.el.select('ul.roo-select2-choices', true).first();
941 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
942 if(this.triggerList){
943 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
946 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
947 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
949 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
950 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
952 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
953 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
955 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
956 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
957 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
960 this.cancelBtn.hide();
965 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
966 _this.list.setWidth(lw);
969 this.list.on('mouseover', this.onViewOver, this);
970 this.list.on('mousemove', this.onViewMove, this);
972 this.list.on('scroll', this.onViewScroll, this);
975 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
976 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
979 this.view = new Roo.View(this.list, this.tpl, {
984 selectedClass: this.selectedClass
987 //this.view.wrapEl.setDisplayed(false);
988 this.view.on('click', this.onViewClick, this);
992 this.store.on('beforeload', this.onBeforeLoad, this);
993 this.store.on('load', this.onLoad, this);
994 this.store.on('loadexception', this.onLoadException, this);
997 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
999 this.inKeyMode = true;
1003 "down" : function(e){
1004 this.inKeyMode = true;
1008 "enter" : function(e){
1009 if(this.fireEvent("specialkey", this, e)){
1010 this.onViewClick(false);
1016 "esc" : function(e){
1017 this.onTickableFooterButtonClick(e, false, false);
1020 "tab" : function(e){
1021 this.fireEvent("specialkey", this, e);
1023 this.onTickableFooterButtonClick(e, false, false);
1030 doRelay : function(e, fn, key){
1031 if(this.scope.isExpanded()){
1032 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1041 this.queryDelay = Math.max(this.queryDelay || 10,
1042 this.mode == 'local' ? 10 : 250);
1045 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1048 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1051 if(this.editable !== false){
1052 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1055 this.indicator = this.indicatorEl();
1058 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1059 this.indicator.hide();
1064 onDestroy : function(){
1066 this.view.setStore(null);
1067 this.view.el.removeAllListeners();
1068 this.view.el.remove();
1069 this.view.purgeListeners();
1072 this.list.dom.innerHTML = '';
1076 this.store.un('beforeload', this.onBeforeLoad, this);
1077 this.store.un('load', this.onLoad, this);
1078 this.store.un('loadexception', this.onLoadException, this);
1080 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
1084 fireKey : function(e){
1085 if(e.isNavKeyPress() && !this.list.isVisible()){
1086 this.fireEvent("specialkey", this, e);
1091 onResize: function(w, h)
1095 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
1097 // if(typeof w != 'number'){
1098 // // we do not handle it!?!?
1101 // var tw = this.trigger.getWidth();
1102 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1103 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1105 // this.inputEl().setWidth( this.adjustWidth('input', x));
1107 // //this.trigger.setStyle('left', x+'px');
1109 // if(this.list && this.listWidth === undefined){
1110 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1111 // this.list.setWidth(lw);
1112 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1120 * Allow or prevent the user from directly editing the field text. If false is passed,
1121 * the user will only be able to select from the items defined in the dropdown list. This method
1122 * is the runtime equivalent of setting the 'editable' config option at config time.
1123 * @param {Boolean} value True to allow the user to directly edit the field text
1125 setEditable : function(value){
1126 if(value == this.editable){
1129 this.editable = value;
1131 this.inputEl().dom.setAttribute('readOnly', true);
1132 this.inputEl().on('mousedown', this.onTriggerClick, this);
1133 this.inputEl().addClass('x-combo-noedit');
1135 this.inputEl().dom.removeAttribute('readOnly');
1136 this.inputEl().un('mousedown', this.onTriggerClick, this);
1137 this.inputEl().removeClass('x-combo-noedit');
1143 onBeforeLoad : function(combo,opts){
1148 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1150 this.restrictHeight();
1151 this.selectedIndex = -1;
1155 onLoad : function(){
1157 this.hasQuery = false;
1163 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1164 this.loading.hide();
1167 if(this.store.getCount() > 0){
1170 this.restrictHeight();
1171 if(this.lastQuery == this.allQuery){
1172 if(this.editable && !this.tickable){
1173 this.inputEl().dom.select();
1177 !this.selectByValue(this.value, true) &&
1180 !this.store.lastOptions ||
1181 typeof(this.store.lastOptions.add) == 'undefined' ||
1182 this.store.lastOptions.add != true
1185 this.select(0, true);
1191 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1192 this.taTask.delay(this.typeAheadDelay);
1196 this.onEmptyResults();
1202 onLoadException : function()
1204 this.hasQuery = false;
1206 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1207 this.loading.hide();
1210 if(this.tickable && this.editable){
1215 // only causes errors at present
1216 //Roo.log(this.store.reader.jsonData);
1217 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1219 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1225 onTypeAhead : function(){
1226 if(this.store.getCount() > 0){
1227 var r = this.store.getAt(0);
1228 var newValue = r.data[this.displayField];
1229 var len = newValue.length;
1230 var selStart = this.getRawValue().length;
1232 if(selStart != len){
1233 this.setRawValue(newValue);
1234 this.selectText(selStart, newValue.length);
1240 onSelect : function(record, index){
1242 if(this.fireEvent('beforeselect', this, record, index) !== false){
1244 this.setFromData(index > -1 ? record.data : false);
1247 this.fireEvent('select', this, record, index);
1252 * Returns the currently selected field value or empty string if no value is set.
1253 * @return {String} value The selected value
1255 getValue : function()
1257 if(Roo.isIOS && this.useNativeIOS){
1258 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1262 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1265 if(this.valueField){
1266 return typeof this.value != 'undefined' ? this.value : '';
1268 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
1272 getRawValue : function()
1274 if(Roo.isIOS && this.useNativeIOS){
1275 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1278 var v = this.inputEl().getValue();
1284 * Clears any text/value currently set in the field
1286 clearValue : function(){
1288 if(this.hiddenField){
1289 this.hiddenField.dom.value = '';
1292 this.setRawValue('');
1293 this.lastSelectionText = '';
1294 this.lastData = false;
1296 var close = this.closeTriggerEl();
1307 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1308 * will be displayed in the field. If the value does not match the data value of an existing item,
1309 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1310 * Otherwise the field will be blank (although the value will still be set).
1311 * @param {String} value The value to match
1313 setValue : function(v)
1315 if(Roo.isIOS && this.useNativeIOS){
1316 this.setIOSValue(v);
1326 if(this.valueField){
1327 var r = this.findRecord(this.valueField, v);
1329 text = r.data[this.displayField];
1330 }else if(this.valueNotFoundText !== undefined){
1331 text = this.valueNotFoundText;
1334 this.lastSelectionText = text;
1335 if(this.hiddenField){
1336 this.hiddenField.dom.value = v;
1338 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
1341 var close = this.closeTriggerEl();
1344 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1350 * @property {Object} the last set data for the element
1355 * Sets the value of the field based on a object which is related to the record format for the store.
1356 * @param {Object} value the value to set as. or false on reset?
1358 setFromData : function(o){
1365 var dv = ''; // display value
1366 var vv = ''; // value value..
1368 if (this.displayField) {
1369 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1371 // this is an error condition!!!
1372 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1375 if(this.valueField){
1376 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1379 var close = this.closeTriggerEl();
1382 if(dv.length || vv * 1 > 0){
1384 this.blockFocus=true;
1390 if(this.hiddenField){
1391 this.hiddenField.dom.value = vv;
1393 this.lastSelectionText = dv;
1394 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1398 // no hidden field.. - we store the value in 'value', but still display
1399 // display field!!!!
1400 this.lastSelectionText = dv;
1401 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1409 // overridden so that last data is reset..
1416 this.setValue(this.originalValue);
1417 //this.clearInvalid();
1418 this.lastData = false;
1420 this.view.clearSelections();
1426 findRecord : function(prop, value){
1428 if(this.store.getCount() > 0){
1429 this.store.each(function(r){
1430 if(r.data[prop] == value){
1442 // returns hidden if it's set..
1443 if (!this.rendered) {return ''};
1444 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1448 onViewMove : function(e, t){
1449 this.inKeyMode = false;
1453 onViewOver : function(e, t){
1454 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1457 var item = this.view.findItemFromChild(t);
1460 var index = this.view.indexOf(item);
1461 this.select(index, false);
1466 onViewClick : function(view, doFocus, el, e)
1468 var index = this.view.getSelectedIndexes()[0];
1470 var r = this.store.getAt(index);
1474 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1481 Roo.each(this.tickItems, function(v,k){
1483 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1485 _this.tickItems.splice(k, 1);
1487 if(typeof(e) == 'undefined' && view == false){
1488 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1500 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1501 this.tickItems.push(r.data);
1504 if(typeof(e) == 'undefined' && view == false){
1505 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1512 this.onSelect(r, index);
1514 if(doFocus !== false && !this.blockFocus){
1515 this.inputEl().focus();
1520 restrictHeight : function(){
1521 //this.innerList.dom.style.height = '';
1522 //var inner = this.innerList.dom;
1523 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1524 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1525 //this.list.beginUpdate();
1526 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1527 this.list.alignTo(this.inputEl(), this.listAlign);
1528 this.list.alignTo(this.inputEl(), this.listAlign);
1529 //this.list.endUpdate();
1533 onEmptyResults : function(){
1535 if(this.tickable && this.editable){
1536 this.hasFocus = false;
1537 this.restrictHeight();
1545 * Returns true if the dropdown list is expanded, else false.
1547 isExpanded : function(){
1548 return this.list.isVisible();
1552 * Select an item in the dropdown list by its data value. 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 {String} value The data value of the 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)
1557 * @return {Boolean} True if the value matched an item in the list, else false
1559 selectByValue : function(v, scrollIntoView){
1560 if(v !== undefined && v !== null){
1561 var r = this.findRecord(this.valueField || this.displayField, v);
1563 this.select(this.store.indexOf(r), scrollIntoView);
1571 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1572 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1573 * @param {Number} index The zero-based index of the list item to select
1574 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1575 * selected item if it is not currently in view (defaults to true)
1577 select : function(index, scrollIntoView){
1578 this.selectedIndex = index;
1579 this.view.select(index);
1580 if(scrollIntoView !== false){
1581 var el = this.view.getNode(index);
1583 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1586 this.list.scrollChildIntoView(el, false);
1592 selectNext : function(){
1593 var ct = this.store.getCount();
1595 if(this.selectedIndex == -1){
1597 }else if(this.selectedIndex < ct-1){
1598 this.select(this.selectedIndex+1);
1604 selectPrev : function(){
1605 var ct = this.store.getCount();
1607 if(this.selectedIndex == -1){
1609 }else if(this.selectedIndex != 0){
1610 this.select(this.selectedIndex-1);
1616 onKeyUp : function(e){
1617 if(this.editable !== false && !e.isSpecialKey()){
1618 this.lastKey = e.getKey();
1619 this.dqTask.delay(this.queryDelay);
1624 validateBlur : function(){
1625 return !this.list || !this.list.isVisible();
1629 initQuery : function(){
1631 var v = this.getRawValue();
1633 if(this.tickable && this.editable){
1634 v = this.tickableInputEl().getValue();
1641 doForce : function(){
1642 if(this.inputEl().dom.value.length > 0){
1643 this.inputEl().dom.value =
1644 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1650 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1651 * query allowing the query action to be canceled if needed.
1652 * @param {String} query The SQL query to execute
1653 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1654 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1655 * saved in the current store (defaults to false)
1657 doQuery : function(q, forceAll){
1659 if(q === undefined || q === null){
1668 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1673 forceAll = qe.forceAll;
1674 if(forceAll === true || (q.length >= this.minChars)){
1676 this.hasQuery = true;
1678 if(this.lastQuery != q || this.alwaysQuery){
1680 if(this.mode == 'local'){
1681 this.selectedIndex = -1;
1683 this.store.clearFilter();
1686 if(this.specialFilter){
1687 this.fireEvent('specialfilter', this);
1692 this.store.filter(this.displayField, q);
1695 this.store.fireEvent("datachanged", this.store);
1702 this.store.baseParams[this.queryParam] = q;
1704 var options = {params : this.getParams(q)};
1708 options.params.start = this.page * this.pageSize;
1711 this.store.load(options);
1714 * this code will make the page width larger, at the beginning, the list not align correctly,
1715 * we should expand the list on onLoad
1721 this.selectedIndex = -1;
1726 this.loadNext = false;
1730 getParams : function(q){
1732 //p[this.queryParam] = q;
1736 p.limit = this.pageSize;
1742 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1744 collapse : function(){
1745 if(!this.isExpanded()){
1751 this.hasFocus = false;
1755 this.cancelBtn.hide();
1756 this.trigger.show();
1759 this.tickableInputEl().dom.value = '';
1760 this.tickableInputEl().blur();
1765 Roo.get(document).un('mousedown', this.collapseIf, this);
1766 Roo.get(document).un('mousewheel', this.collapseIf, this);
1767 if (!this.editable) {
1768 Roo.get(document).un('keydown', this.listKeyPress, this);
1770 this.fireEvent('collapse', this);
1776 collapseIf : function(e){
1777 var in_combo = e.within(this.el);
1778 var in_list = e.within(this.list);
1779 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1781 if (in_combo || in_list || is_list) {
1782 //e.stopPropagation();
1787 this.onTickableFooterButtonClick(e, false, false);
1795 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1797 expand : function(){
1799 if(this.isExpanded() || !this.hasFocus){
1803 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1804 this.list.setWidth(lw);
1810 this.restrictHeight();
1814 this.tickItems = Roo.apply([], this.item);
1817 this.cancelBtn.show();
1818 this.trigger.hide();
1821 this.tickableInputEl().focus();
1826 Roo.get(document).on('mousedown', this.collapseIf, this);
1827 Roo.get(document).on('mousewheel', this.collapseIf, this);
1828 if (!this.editable) {
1829 Roo.get(document).on('keydown', this.listKeyPress, this);
1832 this.fireEvent('expand', this);
1836 // Implements the default empty TriggerField.onTriggerClick function
1837 onTriggerClick : function(e)
1839 Roo.log('trigger click');
1841 if(this.disabled || !this.triggerList){
1846 this.loadNext = false;
1848 if(this.isExpanded()){
1850 if (!this.blockFocus) {
1851 this.inputEl().focus();
1855 this.hasFocus = true;
1856 if(this.triggerAction == 'all') {
1857 this.doQuery(this.allQuery, true);
1859 this.doQuery(this.getRawValue());
1861 if (!this.blockFocus) {
1862 this.inputEl().focus();
1867 onTickableTriggerClick : function(e)
1874 this.loadNext = false;
1875 this.hasFocus = true;
1877 if(this.triggerAction == 'all') {
1878 this.doQuery(this.allQuery, true);
1880 this.doQuery(this.getRawValue());
1884 onSearchFieldClick : function(e)
1886 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1887 this.onTickableFooterButtonClick(e, false, false);
1891 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1896 this.loadNext = false;
1897 this.hasFocus = true;
1899 if(this.triggerAction == 'all') {
1900 this.doQuery(this.allQuery, true);
1902 this.doQuery(this.getRawValue());
1906 listKeyPress : function(e)
1908 //Roo.log('listkeypress');
1909 // scroll to first matching element based on key pres..
1910 if (e.isSpecialKey()) {
1913 var k = String.fromCharCode(e.getKey()).toUpperCase();
1916 var csel = this.view.getSelectedNodes();
1917 var cselitem = false;
1919 var ix = this.view.indexOf(csel[0]);
1920 cselitem = this.store.getAt(ix);
1921 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1927 this.store.each(function(v) {
1929 // start at existing selection.
1930 if (cselitem.id == v.id) {
1936 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1937 match = this.store.indexOf(v);
1943 if (match === false) {
1944 return true; // no more action?
1947 this.view.select(match);
1948 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1949 sn.scrollIntoView(sn.dom.parentNode, false);
1952 onViewScroll : function(e, t){
1954 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){
1958 this.hasQuery = true;
1960 this.loading = this.list.select('.loading', true).first();
1962 if(this.loading === null){
1963 this.list.createChild({
1965 cls: 'loading roo-select2-more-results roo-select2-active',
1966 html: 'Loading more results...'
1969 this.loading = this.list.select('.loading', true).first();
1971 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1973 this.loading.hide();
1976 this.loading.show();
1981 this.loadNext = true;
1983 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1988 addItem : function(o)
1990 var dv = ''; // display value
1992 if (this.displayField) {
1993 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1995 // this is an error condition!!!
1996 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
2003 var choice = this.choices.createChild({
2005 cls: 'roo-select2-search-choice',
2014 cls: 'roo-select2-search-choice-close fa fa-times',
2019 }, this.searchField);
2021 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2023 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2031 this.inputEl().dom.value = '';
2036 onRemoveItem : function(e, _self, o)
2040 this.lastItem = Roo.apply([], this.item);
2042 var index = this.item.indexOf(o.data) * 1;
2045 Roo.log('not this item?!');
2049 this.item.splice(index, 1);
2054 this.fireEvent('remove', this, e);
2060 syncValue : function()
2062 if(!this.item.length){
2069 Roo.each(this.item, function(i){
2070 if(_this.valueField){
2071 value.push(i[_this.valueField]);
2078 this.value = value.join(',');
2080 if(this.hiddenField){
2081 this.hiddenField.dom.value = this.value;
2084 this.store.fireEvent("datachanged", this.store);
2089 clearItem : function()
2097 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2105 if(this.tickable && !Roo.isTouch){
2106 this.view.refresh();
2110 inputEl: function ()
2112 if(Roo.isIOS && this.useNativeIOS){
2113 return this.el.select('select.roo-ios-select', true).first();
2116 if(Roo.isTouch && this.mobileTouchView){
2117 return this.el.select('input.form-control',true).first();
2121 return this.searchField;
2124 return this.el.select('input.form-control',true).first();
2127 onTickableFooterButtonClick : function(e, btn, el)
2131 this.lastItem = Roo.apply([], this.item);
2133 if(btn && btn.name == 'cancel'){
2134 this.tickItems = Roo.apply([], this.item);
2143 Roo.each(this.tickItems, function(o){
2151 validate : function()
2153 if(this.getVisibilityEl().hasClass('hidden')){
2157 var v = this.getRawValue();
2160 v = this.getValue();
2163 if(this.disabled || this.allowBlank || v.length){
2172 tickableInputEl : function()
2174 if(!this.tickable || !this.editable){
2175 return this.inputEl();
2178 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2182 getAutoCreateTouchView : function()
2187 cls: 'form-group' //input-group
2193 type : this.inputType,
2194 cls : 'form-control x-combo-noedit',
2195 autocomplete: 'new-password',
2196 placeholder : this.placeholder || '',
2201 input.name = this.name;
2205 input.cls += ' input-' + this.size;
2208 if (this.disabled) {
2209 input.disabled = true;
2213 cls : 'roo-combobox-wrap',
2220 inputblock.cls += ' input-group';
2222 inputblock.cn.unshift({
2224 cls : 'input-group-addon input-group-prepend input-group-text',
2229 if(this.removable && !this.multiple){
2230 inputblock.cls += ' roo-removable';
2232 inputblock.cn.push({
2235 cls : 'roo-combo-removable-btn close'
2239 if(this.hasFeedback && !this.allowBlank){
2241 inputblock.cls += ' has-feedback';
2243 inputblock.cn.push({
2245 cls: 'glyphicon form-control-feedback'
2252 inputblock.cls += (this.before) ? '' : ' input-group';
2254 inputblock.cn.push({
2256 cls : 'input-group-addon input-group-append input-group-text',
2262 var ibwrap = inputblock;
2267 cls: 'roo-select2-choices',
2271 cls: 'roo-select2-search-field',
2284 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2289 cls: 'form-hidden-field'
2295 if(!this.multiple && this.showToggleBtn){
2301 if (this.caret != false) {
2304 cls: 'fa fa-' + this.caret
2311 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2313 Roo.bootstrap.version == 3 ? caret : '',
2316 cls: 'combobox-clear',
2330 combobox.cls += ' roo-select2-container-multi';
2333 var required = this.allowBlank ? {
2335 style: 'display: none'
2338 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2339 tooltip : 'This field is required'
2342 var align = this.labelAlign || this.parentLabelAlign();
2344 if (align ==='left' && this.fieldLabel.length) {
2350 cls : 'control-label col-form-label',
2351 html : this.fieldLabel
2355 cls : 'roo-combobox-wrap ',
2362 var labelCfg = cfg.cn[1];
2363 var contentCfg = cfg.cn[2];
2366 if(this.indicatorpos == 'right'){
2371 cls : 'control-label col-form-label',
2375 html : this.fieldLabel
2381 cls : "roo-combobox-wrap ",
2389 labelCfg = cfg.cn[0];
2390 contentCfg = cfg.cn[1];
2395 if(this.labelWidth > 12){
2396 labelCfg.style = "width: " + this.labelWidth + 'px';
2399 if(this.labelWidth < 13 && this.labelmd == 0){
2400 this.labelmd = this.labelWidth;
2403 if(this.labellg > 0){
2404 labelCfg.cls += ' col-lg-' + this.labellg;
2405 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2408 if(this.labelmd > 0){
2409 labelCfg.cls += ' col-md-' + this.labelmd;
2410 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2413 if(this.labelsm > 0){
2414 labelCfg.cls += ' col-sm-' + this.labelsm;
2415 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2418 if(this.labelxs > 0){
2419 labelCfg.cls += ' col-xs-' + this.labelxs;
2420 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2424 } else if ( this.fieldLabel.length) {
2429 cls : 'control-label',
2430 html : this.fieldLabel
2441 if(this.indicatorpos == 'right'){
2445 cls : 'control-label',
2446 html : this.fieldLabel,
2464 var settings = this;
2466 ['xs','sm','md','lg'].map(function(size){
2467 if (settings[size]) {
2468 cfg.cls += ' col-' + size + '-' + settings[size];
2475 initTouchView : function()
2477 this.renderTouchView();
2479 this.touchViewEl.on('scroll', function(){
2480 this.el.dom.scrollTop = 0;
2483 this.originalValue = this.getValue();
2485 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2487 this.inputEl().on("click", this.showTouchView, this);
2488 if (this.triggerEl) {
2489 this.triggerEl.on("click", this.showTouchView, this);
2493 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2494 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2496 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2498 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2499 this.store.on('load', this.onTouchViewLoad, this);
2500 this.store.on('loadexception', this.onTouchViewLoadException, this);
2502 if(this.hiddenName){
2504 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2506 this.hiddenField.dom.value =
2507 this.hiddenValue !== undefined ? this.hiddenValue :
2508 this.value !== undefined ? this.value : '';
2510 this.el.dom.removeAttribute('name');
2511 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2515 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2516 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2519 if(this.removable && !this.multiple){
2520 var close = this.closeTriggerEl();
2522 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2523 close.on('click', this.removeBtnClick, this, close);
2527 * fix the bug in Safari iOS8
2529 this.inputEl().on("focus", function(e){
2530 document.activeElement.blur();
2533 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2540 renderTouchView : function()
2542 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.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','show']); }).defer(50);
2593 this.touchViewEl.addClass(['in','show']);
2596 if(this._touchViewMask){
2597 Roo.get(document.body).addClass("x-body-masked");
2598 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2599 this._touchViewMask.setStyle('z-index', 10000);
2600 this._touchViewMask.addClass('show');
2603 this.doTouchViewQuery();
2607 hideTouchView : function()
2609 this.touchViewEl.removeClass(['in','show']);
2613 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2615 this.touchViewEl.setStyle('display', 'none');
2618 if(this._touchViewMask){
2619 this._touchViewMask.removeClass('show');
2620 Roo.get(document.body).removeClass("x-body-masked");
2624 setTouchViewValue : function()
2631 Roo.each(this.tickItems, function(o){
2636 this.hideTouchView();
2639 doTouchViewQuery : function()
2648 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2652 if(!this.alwaysQuery || this.mode == 'local'){
2653 this.onTouchViewLoad();
2660 onTouchViewBeforeLoad : function(combo,opts)
2666 onTouchViewLoad : function()
2668 if(this.store.getCount() < 1){
2669 this.onTouchViewEmptyResults();
2673 this.clearTouchView();
2675 var rawValue = this.getRawValue();
2677 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
2679 this.tickItems = [];
2681 this.store.data.each(function(d, rowIndex){
2682 var row = this.touchViewListGroup.createChild(template);
2684 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2685 row.addClass(d.data.cls);
2688 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2691 html : d.data[this.displayField]
2694 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2695 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2698 row.removeClass('selected');
2699 if(!this.multiple && this.valueField &&
2700 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2703 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2704 row.addClass('selected');
2707 if(this.multiple && this.valueField &&
2708 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2712 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2713 this.tickItems.push(d.data);
2716 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2720 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2722 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2724 if(this.modalTitle.length){
2725 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2728 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2730 if(this.mobile_restrict_height && listHeight < bodyHeight){
2731 this.touchViewBodyEl.setHeight(listHeight);
2736 if(firstChecked && listHeight > bodyHeight){
2737 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2742 onTouchViewLoadException : function()
2744 this.hideTouchView();
2747 onTouchViewEmptyResults : function()
2749 this.clearTouchView();
2751 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
2753 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2757 clearTouchView : function()
2759 this.touchViewListGroup.dom.innerHTML = '';
2762 onTouchViewClick : function(e, el, o)
2767 var rowIndex = o.rowIndex;
2769 var r = this.store.getAt(rowIndex);
2771 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2774 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2775 c.dom.removeAttribute('checked');
2778 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2780 this.setFromData(r.data);
2782 var close = this.closeTriggerEl();
2788 this.hideTouchView();
2790 this.fireEvent('select', this, r, rowIndex);
2795 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2796 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2797 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2801 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2802 this.addItem(r.data);
2803 this.tickItems.push(r.data);
2807 getAutoCreateNativeIOS : function()
2810 cls: 'form-group' //input-group,
2815 cls : 'roo-ios-select'
2819 combobox.name = this.name;
2822 if (this.disabled) {
2823 combobox.disabled = true;
2826 var settings = this;
2828 ['xs','sm','md','lg'].map(function(size){
2829 if (settings[size]) {
2830 cfg.cls += ' col-' + size + '-' + settings[size];
2840 initIOSView : function()
2842 this.store.on('load', this.onIOSViewLoad, this);
2847 onIOSViewLoad : function()
2849 if(this.store.getCount() < 1){
2853 this.clearIOSView();
2855 if(this.allowBlank) {
2857 var default_text = '-- SELECT --';
2859 if(this.placeholder.length){
2860 default_text = this.placeholder;
2863 if(this.emptyTitle.length){
2864 default_text += ' - ' + this.emptyTitle + ' -';
2867 var opt = this.inputEl().createChild({
2874 o[this.valueField] = 0;
2875 o[this.displayField] = default_text;
2877 this.ios_options.push({
2884 this.store.data.each(function(d, rowIndex){
2888 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2889 html = d.data[this.displayField];
2894 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2895 value = d.data[this.valueField];
2904 if(this.value == d.data[this.valueField]){
2905 option['selected'] = true;
2908 var opt = this.inputEl().createChild(option);
2910 this.ios_options.push({
2917 this.inputEl().on('change', function(){
2918 this.fireEvent('select', this);
2923 clearIOSView: function()
2925 this.inputEl().dom.innerHTML = '';
2927 this.ios_options = [];
2930 setIOSValue: function(v)
2934 if(!this.ios_options){
2938 Roo.each(this.ios_options, function(opts){
2940 opts.el.dom.removeAttribute('selected');
2942 if(opts.data[this.valueField] != v){
2946 opts.el.dom.setAttribute('selected', true);
2952 * @cfg {Boolean} grow
2956 * @cfg {Number} growMin
2960 * @cfg {Number} growMax
2969 Roo.apply(Roo.bootstrap.form.ComboBox, {
2973 cls: 'modal-header',
2995 cls: 'list-group-item',
2999 cls: 'roo-combobox-list-group-item-value'
3003 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3017 listItemCheckbox : {
3019 cls: 'list-group-item',
3023 cls: 'roo-combobox-list-group-item-value'
3027 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3043 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3048 cls: 'modal-footer',
3056 cls: 'col-xs-6 text-left',
3059 cls: 'btn btn-danger roo-touch-view-cancel',
3065 cls: 'col-xs-6 text-right',
3068 cls: 'btn btn-success roo-touch-view-ok',
3079 Roo.apply(Roo.bootstrap.form.ComboBox, {
3081 touchViewTemplate : {
3083 cls: 'modal fade roo-combobox-touch-view',
3087 cls: 'modal-dialog',
3088 style : 'position:fixed', // we have to fix position....
3092 cls: 'modal-content',
3094 Roo.bootstrap.form.ComboBox.header,
3095 Roo.bootstrap.form.ComboBox.body,
3096 Roo.bootstrap.form.ComboBox.footer