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)
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'
507 if (Roo.bootstrap.version == 4) {
510 style : 'display:none'
513 if (align ==='left' && this.fieldLabel.length) {
515 cfg.cls += ' roo-form-group-label-left' + (Roo.bootstrap.version == 4 ? ' row' : '');
522 cls : 'control-label col-form-label',
523 html : this.fieldLabel
535 var labelCfg = cfg.cn[1];
536 var contentCfg = cfg.cn[2];
539 if(this.indicatorpos == 'right'){
545 cls : 'control-label col-form-label',
549 html : this.fieldLabel
565 labelCfg = cfg.cn[0];
566 contentCfg = cfg.cn[1];
570 if(this.labelWidth > 12){
571 labelCfg.style = "width: " + this.labelWidth + 'px';
573 if(this.width * 1 > 0){
574 contentCfg.style = "width: " + this.width + 'px';
576 if(this.labelWidth < 13 && this.labelmd == 0){
577 this.labelmd = this.labelWidth;
580 if(this.labellg > 0){
581 labelCfg.cls += ' col-lg-' + this.labellg;
582 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
585 if(this.labelmd > 0){
586 labelCfg.cls += ' col-md-' + this.labelmd;
587 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
590 if(this.labelsm > 0){
591 labelCfg.cls += ' col-sm-' + this.labelsm;
592 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
595 if(this.labelxs > 0){
596 labelCfg.cls += ' col-xs-' + this.labelxs;
597 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
601 } else if ( this.fieldLabel.length) {
602 // Roo.log(" label");
607 //cls : 'input-group-addon',
608 html : this.fieldLabel
613 if(this.indicatorpos == 'right'){
617 //cls : 'input-group-addon',
618 html : this.fieldLabel
628 // Roo.log(" no label && no align");
635 ['xs','sm','md','lg'].map(function(size){
636 if (settings[size]) {
637 cfg.cls += ' col-' + size + '-' + settings[size];
645 _initEventsCalled : false,
648 initEvents: function()
650 if (this._initEventsCalled) { // as we call render... prevent looping...
653 this._initEventsCalled = true;
656 throw "can not find store for combo";
659 this.indicator = this.indicatorEl();
661 this.store = Roo.factory(this.store, Roo.data);
662 this.store.parent = this;
664 // if we are building from html. then this element is so complex, that we can not really
665 // use the rendered HTML.
666 // so we have to trash and replace the previous code.
667 if (Roo.XComponent.build_from_html) {
668 // remove this element....
669 var e = this.el.dom, k=0;
670 while (e ) { e = e.previousSibling; ++k;}
675 this.rendered = false;
677 this.render(this.parent().getChildContainer(true), k);
680 if(Roo.isIOS && this.useNativeIOS){
689 if(Roo.isTouch && this.mobileTouchView){
690 this.initTouchView();
695 this.initTickableEvents();
699 Roo.bootstrap.form.ComboBox.superclass.initEvents.call(this);
703 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
705 this.hiddenField.dom.value =
706 this.hiddenValue !== undefined ? this.hiddenValue :
707 this.value !== undefined ? this.value : '';
709 // prevent input submission
710 this.el.dom.removeAttribute('name');
711 this.hiddenField.dom.setAttribute('name', this.hiddenName);
716 // this.el.dom.setAttribute('autocomplete', 'off');
719 var cls = 'x-combo-list';
721 //this.list = new Roo.Layer({
722 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
728 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
729 _this.list.setWidth(lw);
732 this.list.on('mouseover', this.onViewOver, this);
733 this.list.on('mousemove', this.onViewMove, this);
734 this.list.on('scroll', this.onViewScroll, this);
737 this.list.swallowEvent('mousewheel');
738 this.assetHeight = 0;
741 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
742 this.assetHeight += this.header.getHeight();
745 this.innerList = this.list.createChild({cls:cls+'-inner'});
746 this.innerList.on('mouseover', this.onViewOver, this);
747 this.innerList.on('mousemove', this.onViewMove, this);
748 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
750 if(this.allowBlank && !this.pageSize && !this.disableClear){
751 this.footer = this.list.createChild({cls:cls+'-ft'});
752 this.pageTb = new Roo.Toolbar(this.footer);
756 this.footer = this.list.createChild({cls:cls+'-ft'});
757 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
758 {pageSize: this.pageSize});
762 if (this.pageTb && this.allowBlank && !this.disableClear) {
764 this.pageTb.add(new Roo.Toolbar.Fill(), {
765 cls: 'x-btn-icon x-btn-clear',
771 _this.onSelect(false, -1);
776 this.assetHeight += this.footer.getHeight();
781 this.tpl = Roo.bootstrap.version == 4 ?
782 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
783 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
786 this.view = new Roo.View(this.list, this.tpl, {
787 singleSelect:true, store: this.store, selectedClass: this.selectedClass
789 //this.view.wrapEl.setDisplayed(false);
790 this.view.on('click', this.onViewClick, this);
793 this.store.on('beforeload', this.onBeforeLoad, this);
794 this.store.on('load', this.onLoad, this);
795 this.store.on('loadexception', this.onLoadException, this);
798 this.resizer = new Roo.Resizable(this.list, {
799 pinned:true, handles:'se'
801 this.resizer.on('resize', function(r, w, h){
802 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
804 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
805 this.restrictHeight();
807 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
811 this.editable = true;
812 this.setEditable(false);
817 if (typeof(this.events.add.listeners) != 'undefined') {
819 this.addicon = this.wrap.createChild(
820 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
822 this.addicon.on('click', function(e) {
823 this.fireEvent('add', this);
826 if (typeof(this.events.edit.listeners) != 'undefined') {
828 this.editicon = this.wrap.createChild(
829 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
831 this.editicon.setStyle('margin-left', '40px');
833 this.editicon.on('click', function(e) {
835 // we fire even if inothing is selected..
836 this.fireEvent('edit', this, this.lastData );
842 this.keyNav = new Roo.KeyNav(this.inputEl(), {
844 this.inKeyMode = true;
848 "down" : function(e){
849 if(!this.isExpanded()){
850 this.onTriggerClick();
852 this.inKeyMode = true;
857 "enter" : function(e){
858 // this.onViewClick();
862 if(this.fireEvent("specialkey", this, e)){
863 this.onViewClick(false);
876 if(this.fireEvent("specialkey", this, e)){
877 this.onViewClick(false);
885 doRelay : function(foo, bar, hname){
886 if(hname == 'down' || this.scope.isExpanded()){
887 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
896 this.queryDelay = Math.max(this.queryDelay || 10,
897 this.mode == 'local' ? 10 : 250);
900 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
903 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
905 if(this.editable !== false){
906 this.inputEl().on("keyup", this.onKeyUp, this);
908 if(this.forceSelection){
909 this.inputEl().on('blur', this.doForce, this);
913 this.choices = this.el.select('ul.roo-select2-choices', true).first();
914 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
918 initTickableEvents: function()
924 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
926 this.hiddenField.dom.value =
927 this.hiddenValue !== undefined ? this.hiddenValue :
928 this.value !== undefined ? this.value : '';
930 // prevent input submission
931 this.el.dom.removeAttribute('name');
932 this.hiddenField.dom.setAttribute('name', this.hiddenName);
937 // this.list = this.el.select('ul.dropdown-menu',true).first();
939 this.choices = this.el.select('ul.roo-select2-choices', true).first();
940 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
941 if(this.triggerList){
942 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
945 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
946 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
948 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
949 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
951 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
952 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
954 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
955 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
956 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
959 this.cancelBtn.hide();
964 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
965 _this.list.setWidth(lw);
968 this.list.on('mouseover', this.onViewOver, this);
969 this.list.on('mousemove', this.onViewMove, this);
971 this.list.on('scroll', this.onViewScroll, this);
974 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
975 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
978 this.view = new Roo.View(this.list, this.tpl, {
983 selectedClass: this.selectedClass
986 //this.view.wrapEl.setDisplayed(false);
987 this.view.on('click', this.onViewClick, this);
991 this.store.on('beforeload', this.onBeforeLoad, this);
992 this.store.on('load', this.onLoad, this);
993 this.store.on('loadexception', this.onLoadException, this);
996 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
998 this.inKeyMode = true;
1002 "down" : function(e){
1003 this.inKeyMode = true;
1007 "enter" : function(e){
1008 if(this.fireEvent("specialkey", this, e)){
1009 this.onViewClick(false);
1015 "esc" : function(e){
1016 this.onTickableFooterButtonClick(e, false, false);
1019 "tab" : function(e){
1020 this.fireEvent("specialkey", this, e);
1022 this.onTickableFooterButtonClick(e, false, false);
1029 doRelay : function(e, fn, key){
1030 if(this.scope.isExpanded()){
1031 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1040 this.queryDelay = Math.max(this.queryDelay || 10,
1041 this.mode == 'local' ? 10 : 250);
1044 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1047 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1050 if(this.editable !== false){
1051 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1054 this.indicator = this.indicatorEl();
1057 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1058 this.indicator.hide();
1063 onDestroy : function(){
1065 this.view.setStore(null);
1066 this.view.el.removeAllListeners();
1067 this.view.el.remove();
1068 this.view.purgeListeners();
1071 this.list.dom.innerHTML = '';
1075 this.store.un('beforeload', this.onBeforeLoad, this);
1076 this.store.un('load', this.onLoad, this);
1077 this.store.un('loadexception', this.onLoadException, this);
1079 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
1083 fireKey : function(e){
1084 if(e.isNavKeyPress() && !this.list.isVisible()){
1085 this.fireEvent("specialkey", this, e);
1090 onResize: function(w, h)
1094 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
1096 // if(typeof w != 'number'){
1097 // // we do not handle it!?!?
1100 // var tw = this.trigger.getWidth();
1101 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1102 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1104 // this.inputEl().setWidth( this.adjustWidth('input', x));
1106 // //this.trigger.setStyle('left', x+'px');
1108 // if(this.list && this.listWidth === undefined){
1109 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1110 // this.list.setWidth(lw);
1111 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1119 * Allow or prevent the user from directly editing the field text. If false is passed,
1120 * the user will only be able to select from the items defined in the dropdown list. This method
1121 * is the runtime equivalent of setting the 'editable' config option at config time.
1122 * @param {Boolean} value True to allow the user to directly edit the field text
1124 setEditable : function(value){
1125 if(value == this.editable){
1128 this.editable = value;
1130 this.inputEl().dom.setAttribute('readOnly', true);
1131 this.inputEl().on('mousedown', this.onTriggerClick, this);
1132 this.inputEl().addClass('x-combo-noedit');
1134 this.inputEl().dom.removeAttribute('readOnly');
1135 this.inputEl().un('mousedown', this.onTriggerClick, this);
1136 this.inputEl().removeClass('x-combo-noedit');
1142 onBeforeLoad : function(combo,opts){
1147 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1149 this.restrictHeight();
1150 this.selectedIndex = -1;
1154 onLoad : function(){
1156 this.hasQuery = false;
1162 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1163 this.loading.hide();
1166 if(this.store.getCount() > 0){
1169 this.restrictHeight();
1170 if(this.lastQuery == this.allQuery){
1171 if(this.editable && !this.tickable){
1172 this.inputEl().dom.select();
1176 !this.selectByValue(this.value, true) &&
1179 !this.store.lastOptions ||
1180 typeof(this.store.lastOptions.add) == 'undefined' ||
1181 this.store.lastOptions.add != true
1184 this.select(0, true);
1190 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1191 this.taTask.delay(this.typeAheadDelay);
1195 this.onEmptyResults();
1201 onLoadException : function()
1203 this.hasQuery = false;
1205 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1206 this.loading.hide();
1209 if(this.tickable && this.editable){
1214 // only causes errors at present
1215 //Roo.log(this.store.reader.jsonData);
1216 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1218 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1224 onTypeAhead : function(){
1225 if(this.store.getCount() > 0){
1226 var r = this.store.getAt(0);
1227 var newValue = r.data[this.displayField];
1228 var len = newValue.length;
1229 var selStart = this.getRawValue().length;
1231 if(selStart != len){
1232 this.setRawValue(newValue);
1233 this.selectText(selStart, newValue.length);
1239 onSelect : function(record, index){
1241 if(this.fireEvent('beforeselect', this, record, index) !== false){
1243 this.setFromData(index > -1 ? record.data : false);
1246 this.fireEvent('select', this, record, index);
1251 * Returns the currently selected field value or empty string if no value is set.
1252 * @return {String} value The selected value
1254 getValue : function()
1256 if(Roo.isIOS && this.useNativeIOS){
1257 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1261 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1264 if(this.valueField){
1265 return typeof this.value != 'undefined' ? this.value : '';
1267 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
1271 getRawValue : function()
1273 if(Roo.isIOS && this.useNativeIOS){
1274 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1277 var v = this.inputEl().getValue();
1283 * Clears any text/value currently set in the field
1285 clearValue : function(){
1287 if(this.hiddenField){
1288 this.hiddenField.dom.value = '';
1291 this.setRawValue('');
1292 this.lastSelectionText = '';
1293 this.lastData = false;
1295 var close = this.closeTriggerEl();
1306 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1307 * will be displayed in the field. If the value does not match the data value of an existing item,
1308 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1309 * Otherwise the field will be blank (although the value will still be set).
1310 * @param {String} value The value to match
1312 setValue : function(v)
1314 if(Roo.isIOS && this.useNativeIOS){
1315 this.setIOSValue(v);
1325 if(this.valueField){
1326 var r = this.findRecord(this.valueField, v);
1328 text = r.data[this.displayField];
1329 }else if(this.valueNotFoundText !== undefined){
1330 text = this.valueNotFoundText;
1333 this.lastSelectionText = text;
1334 if(this.hiddenField){
1335 this.hiddenField.dom.value = v;
1337 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
1340 var close = this.closeTriggerEl();
1343 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1349 * @property {Object} the last set data for the element
1354 * Sets the value of the field based on a object which is related to the record format for the store.
1355 * @param {Object} value the value to set as. or false on reset?
1357 setFromData : function(o){
1364 var dv = ''; // display value
1365 var vv = ''; // value value..
1367 if (this.displayField) {
1368 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1370 // this is an error condition!!!
1371 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1374 if(this.valueField){
1375 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1378 var close = this.closeTriggerEl();
1381 if(dv.length || vv * 1 > 0){
1383 this.blockFocus=true;
1389 if(this.hiddenField){
1390 this.hiddenField.dom.value = vv;
1392 this.lastSelectionText = dv;
1393 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1397 // no hidden field.. - we store the value in 'value', but still display
1398 // display field!!!!
1399 this.lastSelectionText = dv;
1400 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1408 // overridden so that last data is reset..
1415 this.setValue(this.originalValue);
1416 //this.clearInvalid();
1417 this.lastData = false;
1419 this.view.clearSelections();
1425 findRecord : function(prop, value){
1427 if(this.store.getCount() > 0){
1428 this.store.each(function(r){
1429 if(r.data[prop] == value){
1441 // returns hidden if it's set..
1442 if (!this.rendered) {return ''};
1443 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1447 onViewMove : function(e, t){
1448 this.inKeyMode = false;
1452 onViewOver : function(e, t){
1453 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1456 var item = this.view.findItemFromChild(t);
1459 var index = this.view.indexOf(item);
1460 this.select(index, false);
1465 onViewClick : function(view, doFocus, el, e)
1467 var index = this.view.getSelectedIndexes()[0];
1469 var r = this.store.getAt(index);
1473 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1480 Roo.each(this.tickItems, function(v,k){
1482 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1484 _this.tickItems.splice(k, 1);
1486 if(typeof(e) == 'undefined' && view == false){
1487 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1499 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1500 this.tickItems.push(r.data);
1503 if(typeof(e) == 'undefined' && view == false){
1504 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1511 this.onSelect(r, index);
1513 if(doFocus !== false && !this.blockFocus){
1514 this.inputEl().focus();
1519 restrictHeight : function(){
1520 //this.innerList.dom.style.height = '';
1521 //var inner = this.innerList.dom;
1522 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1523 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1524 //this.list.beginUpdate();
1525 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1526 this.list.alignTo(this.inputEl(), this.listAlign);
1527 this.list.alignTo(this.inputEl(), this.listAlign);
1528 //this.list.endUpdate();
1532 onEmptyResults : function(){
1534 if(this.tickable && this.editable){
1535 this.hasFocus = false;
1536 this.restrictHeight();
1544 * Returns true if the dropdown list is expanded, else false.
1546 isExpanded : function(){
1547 return this.list.isVisible();
1551 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1552 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1553 * @param {String} value The data value of the item to select
1554 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1555 * selected item if it is not currently in view (defaults to true)
1556 * @return {Boolean} True if the value matched an item in the list, else false
1558 selectByValue : function(v, scrollIntoView){
1559 if(v !== undefined && v !== null){
1560 var r = this.findRecord(this.valueField || this.displayField, v);
1562 this.select(this.store.indexOf(r), scrollIntoView);
1570 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1571 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1572 * @param {Number} index The zero-based index of the list item to select
1573 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1574 * selected item if it is not currently in view (defaults to true)
1576 select : function(index, scrollIntoView){
1577 this.selectedIndex = index;
1578 this.view.select(index);
1579 if(scrollIntoView !== false){
1580 var el = this.view.getNode(index);
1582 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1585 this.list.scrollChildIntoView(el, false);
1591 selectNext : function(){
1592 var ct = this.store.getCount();
1594 if(this.selectedIndex == -1){
1596 }else if(this.selectedIndex < ct-1){
1597 this.select(this.selectedIndex+1);
1603 selectPrev : function(){
1604 var ct = this.store.getCount();
1606 if(this.selectedIndex == -1){
1608 }else if(this.selectedIndex != 0){
1609 this.select(this.selectedIndex-1);
1615 onKeyUp : function(e){
1616 if(this.editable !== false && !e.isSpecialKey()){
1617 this.lastKey = e.getKey();
1618 this.dqTask.delay(this.queryDelay);
1623 validateBlur : function(){
1624 return !this.list || !this.list.isVisible();
1628 initQuery : function(){
1630 var v = this.getRawValue();
1632 if(this.tickable && this.editable){
1633 v = this.tickableInputEl().getValue();
1640 doForce : function(){
1641 if(this.inputEl().dom.value.length > 0){
1642 this.inputEl().dom.value =
1643 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1649 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1650 * query allowing the query action to be canceled if needed.
1651 * @param {String} query The SQL query to execute
1652 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1653 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1654 * saved in the current store (defaults to false)
1656 doQuery : function(q, forceAll){
1658 if(q === undefined || q === null){
1667 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1672 forceAll = qe.forceAll;
1673 if(forceAll === true || (q.length >= this.minChars)){
1675 this.hasQuery = true;
1677 if(this.lastQuery != q || this.alwaysQuery){
1679 if(this.mode == 'local'){
1680 this.selectedIndex = -1;
1682 this.store.clearFilter();
1685 if(this.specialFilter){
1686 this.fireEvent('specialfilter', this);
1691 this.store.filter(this.displayField, q);
1694 this.store.fireEvent("datachanged", this.store);
1701 this.store.baseParams[this.queryParam] = q;
1703 var options = {params : this.getParams(q)};
1707 options.params.start = this.page * this.pageSize;
1710 this.store.load(options);
1713 * this code will make the page width larger, at the beginning, the list not align correctly,
1714 * we should expand the list on onLoad
1720 this.selectedIndex = -1;
1725 this.loadNext = false;
1729 getParams : function(q){
1731 //p[this.queryParam] = q;
1735 p.limit = this.pageSize;
1741 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1743 collapse : function(){
1744 if(!this.isExpanded()){
1750 this.hasFocus = false;
1754 this.cancelBtn.hide();
1755 this.trigger.show();
1758 this.tickableInputEl().dom.value = '';
1759 this.tickableInputEl().blur();
1764 Roo.get(document).un('mousedown', this.collapseIf, this);
1765 Roo.get(document).un('mousewheel', this.collapseIf, this);
1766 if (!this.editable) {
1767 Roo.get(document).un('keydown', this.listKeyPress, this);
1769 this.fireEvent('collapse', this);
1775 collapseIf : function(e){
1776 var in_combo = e.within(this.el);
1777 var in_list = e.within(this.list);
1778 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1780 if (in_combo || in_list || is_list) {
1781 //e.stopPropagation();
1786 this.onTickableFooterButtonClick(e, false, false);
1794 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1796 expand : function(){
1798 if(this.isExpanded() || !this.hasFocus){
1802 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1803 this.list.setWidth(lw);
1809 this.restrictHeight();
1813 this.tickItems = Roo.apply([], this.item);
1816 this.cancelBtn.show();
1817 this.trigger.hide();
1820 this.tickableInputEl().focus();
1825 Roo.get(document).on('mousedown', this.collapseIf, this);
1826 Roo.get(document).on('mousewheel', this.collapseIf, this);
1827 if (!this.editable) {
1828 Roo.get(document).on('keydown', this.listKeyPress, this);
1831 this.fireEvent('expand', this);
1835 // Implements the default empty TriggerField.onTriggerClick function
1836 onTriggerClick : function(e)
1838 Roo.log('trigger click');
1840 if(this.disabled || !this.triggerList){
1845 this.loadNext = false;
1847 if(this.isExpanded()){
1849 if (!this.blockFocus) {
1850 this.inputEl().focus();
1854 this.hasFocus = true;
1855 if(this.triggerAction == 'all') {
1856 this.doQuery(this.allQuery, true);
1858 this.doQuery(this.getRawValue());
1860 if (!this.blockFocus) {
1861 this.inputEl().focus();
1866 onTickableTriggerClick : function(e)
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 onSearchFieldClick : function(e)
1885 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1886 this.onTickableFooterButtonClick(e, false, false);
1890 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1895 this.loadNext = false;
1896 this.hasFocus = true;
1898 if(this.triggerAction == 'all') {
1899 this.doQuery(this.allQuery, true);
1901 this.doQuery(this.getRawValue());
1905 listKeyPress : function(e)
1907 //Roo.log('listkeypress');
1908 // scroll to first matching element based on key pres..
1909 if (e.isSpecialKey()) {
1912 var k = String.fromCharCode(e.getKey()).toUpperCase();
1915 var csel = this.view.getSelectedNodes();
1916 var cselitem = false;
1918 var ix = this.view.indexOf(csel[0]);
1919 cselitem = this.store.getAt(ix);
1920 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1926 this.store.each(function(v) {
1928 // start at existing selection.
1929 if (cselitem.id == v.id) {
1935 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1936 match = this.store.indexOf(v);
1942 if (match === false) {
1943 return true; // no more action?
1946 this.view.select(match);
1947 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1948 sn.scrollIntoView(sn.dom.parentNode, false);
1951 onViewScroll : function(e, t){
1953 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){
1957 this.hasQuery = true;
1959 this.loading = this.list.select('.loading', true).first();
1961 if(this.loading === null){
1962 this.list.createChild({
1964 cls: 'loading roo-select2-more-results roo-select2-active',
1965 html: 'Loading more results...'
1968 this.loading = this.list.select('.loading', true).first();
1970 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1972 this.loading.hide();
1975 this.loading.show();
1980 this.loadNext = true;
1982 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1987 addItem : function(o)
1989 var dv = ''; // display value
1991 if (this.displayField) {
1992 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1994 // this is an error condition!!!
1995 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
2002 var choice = this.choices.createChild({
2004 cls: 'roo-select2-search-choice',
2013 cls: 'roo-select2-search-choice-close fa fa-times',
2018 }, this.searchField);
2020 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2022 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2030 this.inputEl().dom.value = '';
2035 onRemoveItem : function(e, _self, o)
2039 this.lastItem = Roo.apply([], this.item);
2041 var index = this.item.indexOf(o.data) * 1;
2044 Roo.log('not this item?!');
2048 this.item.splice(index, 1);
2053 this.fireEvent('remove', this, e);
2059 syncValue : function()
2061 if(!this.item.length){
2068 Roo.each(this.item, function(i){
2069 if(_this.valueField){
2070 value.push(i[_this.valueField]);
2077 this.value = value.join(',');
2079 if(this.hiddenField){
2080 this.hiddenField.dom.value = this.value;
2083 this.store.fireEvent("datachanged", this.store);
2088 clearItem : function()
2096 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2104 if(this.tickable && !Roo.isTouch){
2105 this.view.refresh();
2109 inputEl: function ()
2111 if(Roo.isIOS && this.useNativeIOS){
2112 return this.el.select('select.roo-ios-select', true).first();
2115 if(Roo.isTouch && this.mobileTouchView){
2116 return this.el.select('input.form-control',true).first();
2120 return this.searchField;
2123 return this.el.select('input.form-control',true).first();
2126 onTickableFooterButtonClick : function(e, btn, el)
2130 this.lastItem = Roo.apply([], this.item);
2132 if(btn && btn.name == 'cancel'){
2133 this.tickItems = Roo.apply([], this.item);
2142 Roo.each(this.tickItems, function(o){
2150 validate : function()
2152 if(this.getVisibilityEl().hasClass('hidden')){
2156 var v = this.getRawValue();
2159 v = this.getValue();
2162 if(this.disabled || this.allowBlank || v.length){
2171 tickableInputEl : function()
2173 if(!this.tickable || !this.editable){
2174 return this.inputEl();
2177 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2181 getAutoCreateTouchView : function()
2186 cls: 'form-group' //input-group
2192 type : this.inputType,
2193 cls : 'form-control x-combo-noedit',
2194 autocomplete: 'new-password',
2195 placeholder : this.placeholder || '',
2200 input.name = this.name;
2204 input.cls += ' input-' + this.size;
2207 if (this.disabled) {
2208 input.disabled = true;
2212 cls : 'roo-combobox-wrap',
2219 inputblock.cls += ' input-group';
2221 inputblock.cn.unshift({
2223 cls : 'input-group-addon input-group-prepend input-group-text',
2228 if(this.removable && !this.multiple){
2229 inputblock.cls += ' roo-removable';
2231 inputblock.cn.push({
2234 cls : 'roo-combo-removable-btn close'
2238 if(this.hasFeedback && !this.allowBlank){
2240 inputblock.cls += ' has-feedback';
2242 inputblock.cn.push({
2244 cls: 'glyphicon form-control-feedback'
2251 inputblock.cls += (this.before) ? '' : ' input-group';
2253 inputblock.cn.push({
2255 cls : 'input-group-addon input-group-append input-group-text',
2261 var ibwrap = inputblock;
2266 cls: 'roo-select2-choices',
2270 cls: 'roo-select2-search-field',
2283 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2288 cls: 'form-hidden-field'
2294 if(!this.multiple && this.showToggleBtn){
2300 if (this.caret != false) {
2303 cls: 'fa fa-' + this.caret
2310 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2312 Roo.bootstrap.version == 3 ? caret : '',
2315 cls: 'combobox-clear',
2329 combobox.cls += ' roo-select2-container-multi';
2332 var required = this.allowBlank ? {
2334 style: 'display: none'
2337 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2338 tooltip : 'This field is required'
2341 var align = this.labelAlign || this.parentLabelAlign();
2343 if (align ==='left' && this.fieldLabel.length) {
2349 cls : 'control-label col-form-label',
2350 html : this.fieldLabel
2354 cls : 'roo-combobox-wrap ',
2361 var labelCfg = cfg.cn[1];
2362 var contentCfg = cfg.cn[2];
2365 if(this.indicatorpos == 'right'){
2370 cls : 'control-label col-form-label',
2374 html : this.fieldLabel
2380 cls : "roo-combobox-wrap ",
2388 labelCfg = cfg.cn[0];
2389 contentCfg = cfg.cn[1];
2394 if(this.labelWidth > 12){
2395 labelCfg.style = "width: " + this.labelWidth + 'px';
2398 if(this.labelWidth < 13 && this.labelmd == 0){
2399 this.labelmd = this.labelWidth;
2402 if(this.labellg > 0){
2403 labelCfg.cls += ' col-lg-' + this.labellg;
2404 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2407 if(this.labelmd > 0){
2408 labelCfg.cls += ' col-md-' + this.labelmd;
2409 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2412 if(this.labelsm > 0){
2413 labelCfg.cls += ' col-sm-' + this.labelsm;
2414 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2417 if(this.labelxs > 0){
2418 labelCfg.cls += ' col-xs-' + this.labelxs;
2419 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2423 } else if ( this.fieldLabel.length) {
2428 cls : 'control-label',
2429 html : this.fieldLabel
2440 if(this.indicatorpos == 'right'){
2444 cls : 'control-label',
2445 html : this.fieldLabel,
2463 var settings = this;
2465 ['xs','sm','md','lg'].map(function(size){
2466 if (settings[size]) {
2467 cfg.cls += ' col-' + size + '-' + settings[size];
2474 initTouchView : function()
2476 this.renderTouchView();
2478 this.touchViewEl.on('scroll', function(){
2479 this.el.dom.scrollTop = 0;
2482 this.originalValue = this.getValue();
2484 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2486 this.inputEl().on("click", this.showTouchView, this);
2487 if (this.triggerEl) {
2488 this.triggerEl.on("click", this.showTouchView, this);
2492 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2493 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2495 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2497 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2498 this.store.on('load', this.onTouchViewLoad, this);
2499 this.store.on('loadexception', this.onTouchViewLoadException, this);
2501 if(this.hiddenName){
2503 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2505 this.hiddenField.dom.value =
2506 this.hiddenValue !== undefined ? this.hiddenValue :
2507 this.value !== undefined ? this.value : '';
2509 this.el.dom.removeAttribute('name');
2510 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2514 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2515 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2518 if(this.removable && !this.multiple){
2519 var close = this.closeTriggerEl();
2521 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2522 close.on('click', this.removeBtnClick, this, close);
2526 * fix the bug in Safari iOS8
2528 this.inputEl().on("focus", function(e){
2529 document.activeElement.blur();
2532 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2539 renderTouchView : function()
2541 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.ComboBox.touchViewTemplate);
2542 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2544 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2545 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2547 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2548 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2549 this.touchViewBodyEl.setStyle('overflow', 'auto');
2551 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2552 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2554 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2555 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2559 showTouchView : function()
2565 this.touchViewHeaderEl.hide();
2567 if(this.modalTitle.length){
2568 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2569 this.touchViewHeaderEl.show();
2572 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2573 this.touchViewEl.show();
2575 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2577 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2578 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2580 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2582 if(this.modalTitle.length){
2583 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2586 this.touchViewBodyEl.setHeight(bodyHeight);
2590 (function(){ _this.touchViewEl.addClass(['in','show']); }).defer(50);
2592 this.touchViewEl.addClass(['in','show']);
2595 if(this._touchViewMask){
2596 Roo.get(document.body).addClass("x-body-masked");
2597 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2598 this._touchViewMask.setStyle('z-index', 10000);
2599 this._touchViewMask.addClass('show');
2602 this.doTouchViewQuery();
2606 hideTouchView : function()
2608 this.touchViewEl.removeClass(['in','show']);
2612 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2614 this.touchViewEl.setStyle('display', 'none');
2617 if(this._touchViewMask){
2618 this._touchViewMask.removeClass('show');
2619 Roo.get(document.body).removeClass("x-body-masked");
2623 setTouchViewValue : function()
2630 Roo.each(this.tickItems, function(o){
2635 this.hideTouchView();
2638 doTouchViewQuery : function()
2647 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2651 if(!this.alwaysQuery || this.mode == 'local'){
2652 this.onTouchViewLoad();
2659 onTouchViewBeforeLoad : function(combo,opts)
2665 onTouchViewLoad : function()
2667 if(this.store.getCount() < 1){
2668 this.onTouchViewEmptyResults();
2672 this.clearTouchView();
2674 var rawValue = this.getRawValue();
2676 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
2678 this.tickItems = [];
2680 this.store.data.each(function(d, rowIndex){
2681 var row = this.touchViewListGroup.createChild(template);
2683 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2684 row.addClass(d.data.cls);
2687 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2690 html : d.data[this.displayField]
2693 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2694 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2697 row.removeClass('selected');
2698 if(!this.multiple && this.valueField &&
2699 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2702 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2703 row.addClass('selected');
2706 if(this.multiple && this.valueField &&
2707 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2711 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2712 this.tickItems.push(d.data);
2715 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2719 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2721 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2723 if(this.modalTitle.length){
2724 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2727 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2729 if(this.mobile_restrict_height && listHeight < bodyHeight){
2730 this.touchViewBodyEl.setHeight(listHeight);
2735 if(firstChecked && listHeight > bodyHeight){
2736 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2741 onTouchViewLoadException : function()
2743 this.hideTouchView();
2746 onTouchViewEmptyResults : function()
2748 this.clearTouchView();
2750 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
2752 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2756 clearTouchView : function()
2758 this.touchViewListGroup.dom.innerHTML = '';
2761 onTouchViewClick : function(e, el, o)
2766 var rowIndex = o.rowIndex;
2768 var r = this.store.getAt(rowIndex);
2770 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2773 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2774 c.dom.removeAttribute('checked');
2777 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2779 this.setFromData(r.data);
2781 var close = this.closeTriggerEl();
2787 this.hideTouchView();
2789 this.fireEvent('select', this, r, rowIndex);
2794 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2795 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2796 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2800 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2801 this.addItem(r.data);
2802 this.tickItems.push(r.data);
2806 getAutoCreateNativeIOS : function()
2809 cls: 'form-group' //input-group,
2814 cls : 'roo-ios-select'
2818 combobox.name = this.name;
2821 if (this.disabled) {
2822 combobox.disabled = true;
2825 var settings = this;
2827 ['xs','sm','md','lg'].map(function(size){
2828 if (settings[size]) {
2829 cfg.cls += ' col-' + size + '-' + settings[size];
2839 initIOSView : function()
2841 this.store.on('load', this.onIOSViewLoad, this);
2846 onIOSViewLoad : function()
2848 if(this.store.getCount() < 1){
2852 this.clearIOSView();
2854 if(this.allowBlank) {
2856 var default_text = '-- SELECT --';
2858 if(this.placeholder.length){
2859 default_text = this.placeholder;
2862 if(this.emptyTitle.length){
2863 default_text += ' - ' + this.emptyTitle + ' -';
2866 var opt = this.inputEl().createChild({
2873 o[this.valueField] = 0;
2874 o[this.displayField] = default_text;
2876 this.ios_options.push({
2883 this.store.data.each(function(d, rowIndex){
2887 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2888 html = d.data[this.displayField];
2893 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2894 value = d.data[this.valueField];
2903 if(this.value == d.data[this.valueField]){
2904 option['selected'] = true;
2907 var opt = this.inputEl().createChild(option);
2909 this.ios_options.push({
2916 this.inputEl().on('change', function(){
2917 this.fireEvent('select', this);
2922 clearIOSView: function()
2924 this.inputEl().dom.innerHTML = '';
2926 this.ios_options = [];
2929 setIOSValue: function(v)
2933 if(!this.ios_options){
2937 Roo.each(this.ios_options, function(opts){
2939 opts.el.dom.removeAttribute('selected');
2941 if(opts.data[this.valueField] != v){
2945 opts.el.dom.setAttribute('selected', true);
2951 * @cfg {Boolean} grow
2955 * @cfg {Number} growMin
2959 * @cfg {Number} growMax
2968 Roo.apply(Roo.bootstrap.form.ComboBox, {
2972 cls: 'modal-header',
2994 cls: 'list-group-item',
2998 cls: 'roo-combobox-list-group-item-value'
3002 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3016 listItemCheckbox : {
3018 cls: 'list-group-item',
3022 cls: 'roo-combobox-list-group-item-value'
3026 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3042 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3047 cls: 'modal-footer',
3055 cls: 'col-xs-6 text-left',
3058 cls: 'btn btn-danger roo-touch-view-cancel',
3064 cls: 'col-xs-6 text-right',
3067 cls: 'btn btn-success roo-touch-view-ok',
3078 Roo.apply(Roo.bootstrap.form.ComboBox, {
3080 touchViewTemplate : {
3082 cls: 'modal fade roo-combobox-touch-view',
3086 cls: 'modal-dialog',
3087 style : 'position:fixed', // we have to fix position....
3091 cls: 'modal-content',
3093 Roo.bootstrap.form.ComboBox.header,
3094 Roo.bootstrap.form.ComboBox.body,
3095 Roo.bootstrap.form.ComboBox.footer