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'
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
727 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
728 _this.list.setWidth(lw);
731 this.list.on('mouseover', this.onViewOver, this);
732 this.list.on('mousemove', this.onViewMove, this);
733 this.list.on('scroll', this.onViewScroll, this);
736 this.list.swallowEvent('mousewheel');
737 this.assetHeight = 0;
740 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
741 this.assetHeight += this.header.getHeight();
744 this.innerList = this.list.createChild({cls:cls+'-inner'});
745 this.innerList.on('mouseover', this.onViewOver, this);
746 this.innerList.on('mousemove', this.onViewMove, this);
747 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
749 if(this.allowBlank && !this.pageSize && !this.disableClear){
750 this.footer = this.list.createChild({cls:cls+'-ft'});
751 this.pageTb = new Roo.Toolbar(this.footer);
755 this.footer = this.list.createChild({cls:cls+'-ft'});
756 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
757 {pageSize: this.pageSize});
761 if (this.pageTb && this.allowBlank && !this.disableClear) {
763 this.pageTb.add(new Roo.Toolbar.Fill(), {
764 cls: 'x-btn-icon x-btn-clear',
770 _this.onSelect(false, -1);
775 this.assetHeight += this.footer.getHeight();
780 this.tpl = Roo.bootstrap.version == 4 ?
781 '<a class="dropdown-item" href="#">{' + this.displayField + '}</a>' : // 4 does not need <li> and it get's really confisued.
782 '<li><a class="dropdown-item" href="#">{' + this.displayField + '}</a></li>';
785 this.view = new Roo.View(this.list, this.tpl, {
786 singleSelect:true, store: this.store, selectedClass: this.selectedClass
788 //this.view.wrapEl.setDisplayed(false);
789 this.view.on('click', this.onViewClick, this);
792 this.store.on('beforeload', this.onBeforeLoad, this);
793 this.store.on('load', this.onLoad, this);
794 this.store.on('loadexception', this.onLoadException, this);
797 this.resizer = new Roo.Resizable(this.list, {
798 pinned:true, handles:'se'
800 this.resizer.on('resize', function(r, w, h){
801 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
803 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
804 this.restrictHeight();
806 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
810 this.editable = true;
811 this.setEditable(false);
816 if (typeof(this.events.add.listeners) != 'undefined') {
818 this.addicon = this.wrap.createChild(
819 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
821 this.addicon.on('click', function(e) {
822 this.fireEvent('add', this);
825 if (typeof(this.events.edit.listeners) != 'undefined') {
827 this.editicon = this.wrap.createChild(
828 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
830 this.editicon.setStyle('margin-left', '40px');
832 this.editicon.on('click', function(e) {
834 // we fire even if inothing is selected..
835 this.fireEvent('edit', this, this.lastData );
841 this.keyNav = new Roo.KeyNav(this.inputEl(), {
843 this.inKeyMode = true;
847 "down" : function(e){
848 if(!this.isExpanded()){
849 this.onTriggerClick();
851 this.inKeyMode = true;
856 "enter" : function(e){
857 // this.onViewClick();
861 if(this.fireEvent("specialkey", this, e)){
862 this.onViewClick(false);
875 if(this.fireEvent("specialkey", this, e)){
876 this.onViewClick(false);
884 doRelay : function(foo, bar, hname){
885 if(hname == 'down' || this.scope.isExpanded()){
886 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
895 this.queryDelay = Math.max(this.queryDelay || 10,
896 this.mode == 'local' ? 10 : 250);
899 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
902 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
904 if(this.editable !== false){
905 this.inputEl().on("keyup", this.onKeyUp, this);
907 if(this.forceSelection){
908 this.inputEl().on('blur', this.doForce, this);
912 this.choices = this.el.select('ul.roo-select2-choices', true).first();
913 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
917 initTickableEvents: function()
923 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
925 this.hiddenField.dom.value =
926 this.hiddenValue !== undefined ? this.hiddenValue :
927 this.value !== undefined ? this.value : '';
929 // prevent input submission
930 this.el.dom.removeAttribute('name');
931 this.hiddenField.dom.setAttribute('name', this.hiddenName);
936 // this.list = this.el.select('ul.dropdown-menu',true).first();
938 this.choices = this.el.select('ul.roo-select2-choices', true).first();
939 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
940 if(this.triggerList){
941 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
944 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
945 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
947 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
948 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
950 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
951 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
953 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
954 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
955 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
958 this.cancelBtn.hide();
963 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
964 _this.list.setWidth(lw);
967 this.list.on('mouseover', this.onViewOver, this);
968 this.list.on('mousemove', this.onViewMove, this);
970 this.list.on('scroll', this.onViewScroll, this);
973 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
974 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
977 this.view = new Roo.View(this.list, this.tpl, {
982 selectedClass: this.selectedClass
985 //this.view.wrapEl.setDisplayed(false);
986 this.view.on('click', this.onViewClick, this);
990 this.store.on('beforeload', this.onBeforeLoad, this);
991 this.store.on('load', this.onLoad, this);
992 this.store.on('loadexception', this.onLoadException, this);
995 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
997 this.inKeyMode = true;
1001 "down" : function(e){
1002 this.inKeyMode = true;
1006 "enter" : function(e){
1007 if(this.fireEvent("specialkey", this, e)){
1008 this.onViewClick(false);
1014 "esc" : function(e){
1015 this.onTickableFooterButtonClick(e, false, false);
1018 "tab" : function(e){
1019 this.fireEvent("specialkey", this, e);
1021 this.onTickableFooterButtonClick(e, false, false);
1028 doRelay : function(e, fn, key){
1029 if(this.scope.isExpanded()){
1030 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1039 this.queryDelay = Math.max(this.queryDelay || 10,
1040 this.mode == 'local' ? 10 : 250);
1043 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1046 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1049 if(this.editable !== false){
1050 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1053 this.indicator = this.indicatorEl();
1056 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
1057 this.indicator.hide();
1062 onDestroy : function(){
1064 this.view.setStore(null);
1065 this.view.el.removeAllListeners();
1066 this.view.el.remove();
1067 this.view.purgeListeners();
1070 this.list.dom.innerHTML = '';
1074 this.store.un('beforeload', this.onBeforeLoad, this);
1075 this.store.un('load', this.onLoad, this);
1076 this.store.un('loadexception', this.onLoadException, this);
1078 Roo.bootstrap.form.ComboBox.superclass.onDestroy.call(this);
1082 fireKey : function(e){
1083 if(e.isNavKeyPress() && !this.list.isVisible()){
1084 this.fireEvent("specialkey", this, e);
1089 onResize: function(w, h)
1093 // Roo.bootstrap.form.ComboBox.superclass.onResize.apply(this, arguments);
1095 // if(typeof w != 'number'){
1096 // // we do not handle it!?!?
1099 // var tw = this.trigger.getWidth();
1100 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1101 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1103 // this.inputEl().setWidth( this.adjustWidth('input', x));
1105 // //this.trigger.setStyle('left', x+'px');
1107 // if(this.list && this.listWidth === undefined){
1108 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1109 // this.list.setWidth(lw);
1110 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1118 * Allow or prevent the user from directly editing the field text. If false is passed,
1119 * the user will only be able to select from the items defined in the dropdown list. This method
1120 * is the runtime equivalent of setting the 'editable' config option at config time.
1121 * @param {Boolean} value True to allow the user to directly edit the field text
1123 setEditable : function(value){
1124 if(value == this.editable){
1127 this.editable = value;
1129 this.inputEl().dom.setAttribute('readOnly', true);
1130 this.inputEl().on('mousedown', this.onTriggerClick, this);
1131 this.inputEl().addClass('x-combo-noedit');
1133 this.inputEl().dom.removeAttribute('readOnly');
1134 this.inputEl().un('mousedown', this.onTriggerClick, this);
1135 this.inputEl().removeClass('x-combo-noedit');
1141 onBeforeLoad : function(combo,opts){
1146 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1148 this.restrictHeight();
1149 this.selectedIndex = -1;
1153 onLoad : function(){
1155 this.hasQuery = false;
1161 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1162 this.loading.hide();
1165 if(this.store.getCount() > 0){
1168 this.restrictHeight();
1169 if(this.lastQuery == this.allQuery){
1170 if(this.editable && !this.tickable){
1171 this.inputEl().dom.select();
1175 !this.selectByValue(this.value, true) &&
1178 !this.store.lastOptions ||
1179 typeof(this.store.lastOptions.add) == 'undefined' ||
1180 this.store.lastOptions.add != true
1183 this.select(0, true);
1189 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1190 this.taTask.delay(this.typeAheadDelay);
1194 this.onEmptyResults();
1200 onLoadException : function()
1202 this.hasQuery = false;
1204 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1205 this.loading.hide();
1208 if(this.tickable && this.editable){
1213 // only causes errors at present
1214 //Roo.log(this.store.reader.jsonData);
1215 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1217 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1223 onTypeAhead : function(){
1224 if(this.store.getCount() > 0){
1225 var r = this.store.getAt(0);
1226 var newValue = r.data[this.displayField];
1227 var len = newValue.length;
1228 var selStart = this.getRawValue().length;
1230 if(selStart != len){
1231 this.setRawValue(newValue);
1232 this.selectText(selStart, newValue.length);
1238 onSelect : function(record, index){
1240 if(this.fireEvent('beforeselect', this, record, index) !== false){
1242 this.setFromData(index > -1 ? record.data : false);
1245 this.fireEvent('select', this, record, index);
1250 * Returns the currently selected field value or empty string if no value is set.
1251 * @return {String} value The selected value
1253 getValue : function()
1255 if(Roo.isIOS && this.useNativeIOS){
1256 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1260 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1263 if(this.valueField){
1264 return typeof this.value != 'undefined' ? this.value : '';
1266 return Roo.bootstrap.form.ComboBox.superclass.getValue.call(this);
1270 getRawValue : function()
1272 if(Roo.isIOS && this.useNativeIOS){
1273 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1276 var v = this.inputEl().getValue();
1282 * Clears any text/value currently set in the field
1284 clearValue : function(){
1286 if(this.hiddenField){
1287 this.hiddenField.dom.value = '';
1290 this.setRawValue('');
1291 this.lastSelectionText = '';
1292 this.lastData = false;
1294 var close = this.closeTriggerEl();
1305 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1306 * will be displayed in the field. If the value does not match the data value of an existing item,
1307 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1308 * Otherwise the field will be blank (although the value will still be set).
1309 * @param {String} value The value to match
1311 setValue : function(v)
1313 if(Roo.isIOS && this.useNativeIOS){
1314 this.setIOSValue(v);
1324 if(this.valueField){
1325 var r = this.findRecord(this.valueField, v);
1327 text = r.data[this.displayField];
1328 }else if(this.valueNotFoundText !== undefined){
1329 text = this.valueNotFoundText;
1332 this.lastSelectionText = text;
1333 if(this.hiddenField){
1334 this.hiddenField.dom.value = v;
1336 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, text);
1339 var close = this.closeTriggerEl();
1342 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1348 * @property {Object} the last set data for the element
1353 * Sets the value of the field based on a object which is related to the record format for the store.
1354 * @param {Object} value the value to set as. or false on reset?
1356 setFromData : function(o){
1363 var dv = ''; // display value
1364 var vv = ''; // value value..
1366 if (this.displayField) {
1367 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1369 // this is an error condition!!!
1370 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1373 if(this.valueField){
1374 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1377 var close = this.closeTriggerEl();
1380 if(dv.length || vv * 1 > 0){
1382 this.blockFocus=true;
1388 if(this.hiddenField){
1389 this.hiddenField.dom.value = vv;
1391 this.lastSelectionText = dv;
1392 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1396 // no hidden field.. - we store the value in 'value', but still display
1397 // display field!!!!
1398 this.lastSelectionText = dv;
1399 Roo.bootstrap.form.ComboBox.superclass.setValue.call(this, dv);
1407 // overridden so that last data is reset..
1414 this.setValue(this.originalValue);
1415 //this.clearInvalid();
1416 this.lastData = false;
1418 this.view.clearSelections();
1424 findRecord : function(prop, value){
1426 if(this.store.getCount() > 0){
1427 this.store.each(function(r){
1428 if(r.data[prop] == value){
1440 // returns hidden if it's set..
1441 if (!this.rendered) {return ''};
1442 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1446 onViewMove : function(e, t){
1447 this.inKeyMode = false;
1451 onViewOver : function(e, t){
1452 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1455 var item = this.view.findItemFromChild(t);
1458 var index = this.view.indexOf(item);
1459 this.select(index, false);
1464 onViewClick : function(view, doFocus, el, e)
1466 var index = this.view.getSelectedIndexes()[0];
1468 var r = this.store.getAt(index);
1472 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1479 Roo.each(this.tickItems, function(v,k){
1481 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1483 _this.tickItems.splice(k, 1);
1485 if(typeof(e) == 'undefined' && view == false){
1486 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1498 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1499 this.tickItems.push(r.data);
1502 if(typeof(e) == 'undefined' && view == false){
1503 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1510 this.onSelect(r, index);
1512 if(doFocus !== false && !this.blockFocus){
1513 this.inputEl().focus();
1518 restrictHeight : function(){
1519 //this.innerList.dom.style.height = '';
1520 //var inner = this.innerList.dom;
1521 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1522 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1523 //this.list.beginUpdate();
1524 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1525 this.list.alignTo(this.inputEl(), this.listAlign);
1526 this.list.alignTo(this.inputEl(), this.listAlign);
1527 //this.list.endUpdate();
1531 onEmptyResults : function(){
1533 if(this.tickable && this.editable){
1534 this.hasFocus = false;
1535 this.restrictHeight();
1543 * Returns true if the dropdown list is expanded, else false.
1545 isExpanded : function(){
1546 return this.list.isVisible();
1550 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1551 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1552 * @param {String} value The data value of the item to select
1553 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1554 * selected item if it is not currently in view (defaults to true)
1555 * @return {Boolean} True if the value matched an item in the list, else false
1557 selectByValue : function(v, scrollIntoView){
1558 if(v !== undefined && v !== null){
1559 var r = this.findRecord(this.valueField || this.displayField, v);
1561 this.select(this.store.indexOf(r), scrollIntoView);
1569 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1570 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1571 * @param {Number} index The zero-based index of the list item to select
1572 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1573 * selected item if it is not currently in view (defaults to true)
1575 select : function(index, scrollIntoView){
1576 this.selectedIndex = index;
1577 this.view.select(index);
1578 if(scrollIntoView !== false){
1579 var el = this.view.getNode(index);
1581 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1584 this.list.scrollChildIntoView(el, false);
1590 selectNext : function(){
1591 var ct = this.store.getCount();
1593 if(this.selectedIndex == -1){
1595 }else if(this.selectedIndex < ct-1){
1596 this.select(this.selectedIndex+1);
1602 selectPrev : function(){
1603 var ct = this.store.getCount();
1605 if(this.selectedIndex == -1){
1607 }else if(this.selectedIndex != 0){
1608 this.select(this.selectedIndex-1);
1614 onKeyUp : function(e){
1615 if(this.editable !== false && !e.isSpecialKey()){
1616 this.lastKey = e.getKey();
1617 this.dqTask.delay(this.queryDelay);
1622 validateBlur : function(){
1623 return !this.list || !this.list.isVisible();
1627 initQuery : function(){
1629 var v = this.getRawValue();
1631 if(this.tickable && this.editable){
1632 v = this.tickableInputEl().getValue();
1639 doForce : function(){
1640 if(this.inputEl().dom.value.length > 0){
1641 this.inputEl().dom.value =
1642 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1648 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1649 * query allowing the query action to be canceled if needed.
1650 * @param {String} query The SQL query to execute
1651 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1652 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1653 * saved in the current store (defaults to false)
1655 doQuery : function(q, forceAll){
1657 if(q === undefined || q === null){
1666 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1671 forceAll = qe.forceAll;
1672 if(forceAll === true || (q.length >= this.minChars)){
1674 this.hasQuery = true;
1676 if(this.lastQuery != q || this.alwaysQuery){
1678 if(this.mode == 'local'){
1679 this.selectedIndex = -1;
1681 this.store.clearFilter();
1684 if(this.specialFilter){
1685 this.fireEvent('specialfilter', this);
1690 this.store.filter(this.displayField, q);
1693 this.store.fireEvent("datachanged", this.store);
1700 this.store.baseParams[this.queryParam] = q;
1702 var options = {params : this.getParams(q)};
1706 options.params.start = this.page * this.pageSize;
1709 this.store.load(options);
1712 * this code will make the page width larger, at the beginning, the list not align correctly,
1713 * we should expand the list on onLoad
1719 this.selectedIndex = -1;
1724 this.loadNext = false;
1728 getParams : function(q){
1730 //p[this.queryParam] = q;
1734 p.limit = this.pageSize;
1740 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1742 collapse : function(){
1743 if(!this.isExpanded()){
1749 this.hasFocus = false;
1753 this.cancelBtn.hide();
1754 this.trigger.show();
1757 this.tickableInputEl().dom.value = '';
1758 this.tickableInputEl().blur();
1763 Roo.get(document).un('mousedown', this.collapseIf, this);
1764 Roo.get(document).un('mousewheel', this.collapseIf, this);
1765 if (!this.editable) {
1766 Roo.get(document).un('keydown', this.listKeyPress, this);
1768 this.fireEvent('collapse', this);
1774 collapseIf : function(e){
1775 var in_combo = e.within(this.el);
1776 var in_list = e.within(this.list);
1777 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1779 if (in_combo || in_list || is_list) {
1780 //e.stopPropagation();
1785 this.onTickableFooterButtonClick(e, false, false);
1793 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1795 expand : function(){
1797 if(this.isExpanded() || !this.hasFocus){
1801 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1802 this.list.setWidth(lw);
1808 this.restrictHeight();
1812 this.tickItems = Roo.apply([], this.item);
1815 this.cancelBtn.show();
1816 this.trigger.hide();
1819 this.tickableInputEl().focus();
1824 Roo.get(document).on('mousedown', this.collapseIf, this);
1825 Roo.get(document).on('mousewheel', this.collapseIf, this);
1826 if (!this.editable) {
1827 Roo.get(document).on('keydown', this.listKeyPress, this);
1830 this.fireEvent('expand', this);
1834 // Implements the default empty TriggerField.onTriggerClick function
1835 onTriggerClick : function(e)
1837 Roo.log('trigger click');
1839 if(this.disabled || !this.triggerList){
1844 this.loadNext = false;
1846 if(this.isExpanded()){
1848 if (!this.blockFocus) {
1849 this.inputEl().focus();
1853 this.hasFocus = true;
1854 if(this.triggerAction == 'all') {
1855 this.doQuery(this.allQuery, true);
1857 this.doQuery(this.getRawValue());
1859 if (!this.blockFocus) {
1860 this.inputEl().focus();
1865 onTickableTriggerClick : function(e)
1872 this.loadNext = false;
1873 this.hasFocus = true;
1875 if(this.triggerAction == 'all') {
1876 this.doQuery(this.allQuery, true);
1878 this.doQuery(this.getRawValue());
1882 onSearchFieldClick : function(e)
1884 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1885 this.onTickableFooterButtonClick(e, false, false);
1889 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1894 this.loadNext = false;
1895 this.hasFocus = true;
1897 if(this.triggerAction == 'all') {
1898 this.doQuery(this.allQuery, true);
1900 this.doQuery(this.getRawValue());
1904 listKeyPress : function(e)
1906 //Roo.log('listkeypress');
1907 // scroll to first matching element based on key pres..
1908 if (e.isSpecialKey()) {
1911 var k = String.fromCharCode(e.getKey()).toUpperCase();
1914 var csel = this.view.getSelectedNodes();
1915 var cselitem = false;
1917 var ix = this.view.indexOf(csel[0]);
1918 cselitem = this.store.getAt(ix);
1919 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1925 this.store.each(function(v) {
1927 // start at existing selection.
1928 if (cselitem.id == v.id) {
1934 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1935 match = this.store.indexOf(v);
1941 if (match === false) {
1942 return true; // no more action?
1945 this.view.select(match);
1946 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1947 sn.scrollIntoView(sn.dom.parentNode, false);
1950 onViewScroll : function(e, t){
1952 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){
1956 this.hasQuery = true;
1958 this.loading = this.list.select('.loading', true).first();
1960 if(this.loading === null){
1961 this.list.createChild({
1963 cls: 'loading roo-select2-more-results roo-select2-active',
1964 html: 'Loading more results...'
1967 this.loading = this.list.select('.loading', true).first();
1969 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1971 this.loading.hide();
1974 this.loading.show();
1979 this.loadNext = true;
1981 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1986 addItem : function(o)
1988 var dv = ''; // display value
1990 if (this.displayField) {
1991 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1993 // this is an error condition!!!
1994 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
2001 var choice = this.choices.createChild({
2003 cls: 'roo-select2-search-choice',
2012 cls: 'roo-select2-search-choice-close fa fa-times',
2017 }, this.searchField);
2019 var close = choice.select('a.roo-select2-search-choice-close', true).first();
2021 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
2029 this.inputEl().dom.value = '';
2034 onRemoveItem : function(e, _self, o)
2038 this.lastItem = Roo.apply([], this.item);
2040 var index = this.item.indexOf(o.data) * 1;
2043 Roo.log('not this item?!');
2047 this.item.splice(index, 1);
2052 this.fireEvent('remove', this, e);
2058 syncValue : function()
2060 if(!this.item.length){
2067 Roo.each(this.item, function(i){
2068 if(_this.valueField){
2069 value.push(i[_this.valueField]);
2076 this.value = value.join(',');
2078 if(this.hiddenField){
2079 this.hiddenField.dom.value = this.value;
2082 this.store.fireEvent("datachanged", this.store);
2087 clearItem : function()
2095 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2103 if(this.tickable && !Roo.isTouch){
2104 this.view.refresh();
2108 inputEl: function ()
2110 if(Roo.isIOS && this.useNativeIOS){
2111 return this.el.select('select.roo-ios-select', true).first();
2114 if(Roo.isTouch && this.mobileTouchView){
2115 return this.el.select('input.form-control',true).first();
2119 return this.searchField;
2122 return this.el.select('input.form-control',true).first();
2125 onTickableFooterButtonClick : function(e, btn, el)
2129 this.lastItem = Roo.apply([], this.item);
2131 if(btn && btn.name == 'cancel'){
2132 this.tickItems = Roo.apply([], this.item);
2141 Roo.each(this.tickItems, function(o){
2149 validate : function()
2151 if(this.getVisibilityEl().hasClass('hidden')){
2155 var v = this.getRawValue();
2158 v = this.getValue();
2161 if(this.disabled || this.allowBlank || v.length){
2170 tickableInputEl : function()
2172 if(!this.tickable || !this.editable){
2173 return this.inputEl();
2176 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2180 getAutoCreateTouchView : function()
2185 cls: 'form-group' //input-group
2191 type : this.inputType,
2192 cls : 'form-control x-combo-noedit',
2193 autocomplete: 'new-password',
2194 placeholder : this.placeholder || '',
2199 input.name = this.name;
2203 input.cls += ' input-' + this.size;
2206 if (this.disabled) {
2207 input.disabled = true;
2211 cls : 'roo-combobox-wrap',
2218 inputblock.cls += ' input-group';
2220 inputblock.cn.unshift({
2222 cls : 'input-group-addon input-group-prepend input-group-text',
2227 if(this.removable && !this.multiple){
2228 inputblock.cls += ' roo-removable';
2230 inputblock.cn.push({
2233 cls : 'roo-combo-removable-btn close'
2237 if(this.hasFeedback && !this.allowBlank){
2239 inputblock.cls += ' has-feedback';
2241 inputblock.cn.push({
2243 cls: 'glyphicon form-control-feedback'
2250 inputblock.cls += (this.before) ? '' : ' input-group';
2252 inputblock.cn.push({
2254 cls : 'input-group-addon input-group-append input-group-text',
2260 var ibwrap = inputblock;
2265 cls: 'roo-select2-choices',
2269 cls: 'roo-select2-search-field',
2282 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2287 cls: 'form-hidden-field'
2293 if(!this.multiple && this.showToggleBtn){
2299 if (this.caret != false) {
2302 cls: 'fa fa-' + this.caret
2309 cls : 'input-group-addon input-group-append input-group-text btn dropdown-toggle',
2311 Roo.bootstrap.version == 3 ? caret : '',
2314 cls: 'combobox-clear',
2328 combobox.cls += ' roo-select2-container-multi';
2331 var required = this.allowBlank ? {
2333 style: 'display: none'
2336 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2337 tooltip : 'This field is required'
2340 var align = this.labelAlign || this.parentLabelAlign();
2342 if (align ==='left' && this.fieldLabel.length) {
2348 cls : 'control-label col-form-label',
2349 html : this.fieldLabel
2353 cls : 'roo-combobox-wrap ',
2360 var labelCfg = cfg.cn[1];
2361 var contentCfg = cfg.cn[2];
2364 if(this.indicatorpos == 'right'){
2369 cls : 'control-label col-form-label',
2373 html : this.fieldLabel
2379 cls : "roo-combobox-wrap ",
2387 labelCfg = cfg.cn[0];
2388 contentCfg = cfg.cn[1];
2393 if(this.labelWidth > 12){
2394 labelCfg.style = "width: " + this.labelWidth + 'px';
2397 if(this.labelWidth < 13 && this.labelmd == 0){
2398 this.labelmd = this.labelWidth;
2401 if(this.labellg > 0){
2402 labelCfg.cls += ' col-lg-' + this.labellg;
2403 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
2406 if(this.labelmd > 0){
2407 labelCfg.cls += ' col-md-' + this.labelmd;
2408 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
2411 if(this.labelsm > 0){
2412 labelCfg.cls += ' col-sm-' + this.labelsm;
2413 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
2416 if(this.labelxs > 0){
2417 labelCfg.cls += ' col-xs-' + this.labelxs;
2418 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
2422 } else if ( this.fieldLabel.length) {
2427 cls : 'control-label',
2428 html : this.fieldLabel
2439 if(this.indicatorpos == 'right'){
2443 cls : 'control-label',
2444 html : this.fieldLabel,
2462 var settings = this;
2464 ['xs','sm','md','lg'].map(function(size){
2465 if (settings[size]) {
2466 cfg.cls += ' col-' + size + '-' + settings[size];
2473 initTouchView : function()
2475 this.renderTouchView();
2477 this.touchViewEl.on('scroll', function(){
2478 this.el.dom.scrollTop = 0;
2481 this.originalValue = this.getValue();
2483 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2485 this.inputEl().on("click", this.showTouchView, this);
2486 if (this.triggerEl) {
2487 this.triggerEl.on("click", this.showTouchView, this);
2491 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2492 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2494 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2496 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2497 this.store.on('load', this.onTouchViewLoad, this);
2498 this.store.on('loadexception', this.onTouchViewLoadException, this);
2500 if(this.hiddenName){
2502 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2504 this.hiddenField.dom.value =
2505 this.hiddenValue !== undefined ? this.hiddenValue :
2506 this.value !== undefined ? this.value : '';
2508 this.el.dom.removeAttribute('name');
2509 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2513 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2514 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2517 if(this.removable && !this.multiple){
2518 var close = this.closeTriggerEl();
2520 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2521 close.on('click', this.removeBtnClick, this, close);
2525 * fix the bug in Safari iOS8
2527 this.inputEl().on("focus", function(e){
2528 document.activeElement.blur();
2531 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2538 renderTouchView : function()
2540 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.form.ComboBox.touchViewTemplate);
2541 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2543 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2544 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2546 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2547 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2548 this.touchViewBodyEl.setStyle('overflow', 'auto');
2550 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2551 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2553 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2554 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2558 showTouchView : function()
2564 this.touchViewHeaderEl.hide();
2566 if(this.modalTitle.length){
2567 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2568 this.touchViewHeaderEl.show();
2571 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2572 this.touchViewEl.show();
2574 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
2576 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2577 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2579 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2581 if(this.modalTitle.length){
2582 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2585 this.touchViewBodyEl.setHeight(bodyHeight);
2589 (function(){ _this.touchViewEl.addClass(['in','show']); }).defer(50);
2591 this.touchViewEl.addClass(['in','show']);
2594 if(this._touchViewMask){
2595 Roo.get(document.body).addClass("x-body-masked");
2596 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2597 this._touchViewMask.setStyle('z-index', 10000);
2598 this._touchViewMask.addClass('show');
2601 this.doTouchViewQuery();
2605 hideTouchView : function()
2607 this.touchViewEl.removeClass(['in','show']);
2611 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2613 this.touchViewEl.setStyle('display', 'none');
2616 if(this._touchViewMask){
2617 this._touchViewMask.removeClass('show');
2618 Roo.get(document.body).removeClass("x-body-masked");
2622 setTouchViewValue : function()
2629 Roo.each(this.tickItems, function(o){
2634 this.hideTouchView();
2637 doTouchViewQuery : function()
2646 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2650 if(!this.alwaysQuery || this.mode == 'local'){
2651 this.onTouchViewLoad();
2658 onTouchViewBeforeLoad : function(combo,opts)
2664 onTouchViewLoad : function()
2666 if(this.store.getCount() < 1){
2667 this.onTouchViewEmptyResults();
2671 this.clearTouchView();
2673 var rawValue = this.getRawValue();
2675 var template = (this.multiple) ? Roo.bootstrap.form.ComboBox.listItemCheckbox : Roo.bootstrap.form.ComboBox.listItemRadio;
2677 this.tickItems = [];
2679 this.store.data.each(function(d, rowIndex){
2680 var row = this.touchViewListGroup.createChild(template);
2682 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2683 row.addClass(d.data.cls);
2686 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2689 html : d.data[this.displayField]
2692 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2693 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2696 row.removeClass('selected');
2697 if(!this.multiple && this.valueField &&
2698 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2701 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2702 row.addClass('selected');
2705 if(this.multiple && this.valueField &&
2706 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2710 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2711 this.tickItems.push(d.data);
2714 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2718 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2720 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2722 if(this.modalTitle.length){
2723 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2726 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
2728 if(this.mobile_restrict_height && listHeight < bodyHeight){
2729 this.touchViewBodyEl.setHeight(listHeight);
2734 if(firstChecked && listHeight > bodyHeight){
2735 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2740 onTouchViewLoadException : function()
2742 this.hideTouchView();
2745 onTouchViewEmptyResults : function()
2747 this.clearTouchView();
2749 this.touchViewListGroup.createChild(Roo.bootstrap.form.ComboBox.emptyResult);
2751 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2755 clearTouchView : function()
2757 this.touchViewListGroup.dom.innerHTML = '';
2760 onTouchViewClick : function(e, el, o)
2765 var rowIndex = o.rowIndex;
2767 var r = this.store.getAt(rowIndex);
2769 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2772 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2773 c.dom.removeAttribute('checked');
2776 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2778 this.setFromData(r.data);
2780 var close = this.closeTriggerEl();
2786 this.hideTouchView();
2788 this.fireEvent('select', this, r, rowIndex);
2793 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2794 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2795 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2799 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2800 this.addItem(r.data);
2801 this.tickItems.push(r.data);
2805 getAutoCreateNativeIOS : function()
2808 cls: 'form-group' //input-group,
2813 cls : 'roo-ios-select'
2817 combobox.name = this.name;
2820 if (this.disabled) {
2821 combobox.disabled = true;
2824 var settings = this;
2826 ['xs','sm','md','lg'].map(function(size){
2827 if (settings[size]) {
2828 cfg.cls += ' col-' + size + '-' + settings[size];
2838 initIOSView : function()
2840 this.store.on('load', this.onIOSViewLoad, this);
2845 onIOSViewLoad : function()
2847 if(this.store.getCount() < 1){
2851 this.clearIOSView();
2853 if(this.allowBlank) {
2855 var default_text = '-- SELECT --';
2857 if(this.placeholder.length){
2858 default_text = this.placeholder;
2861 if(this.emptyTitle.length){
2862 default_text += ' - ' + this.emptyTitle + ' -';
2865 var opt = this.inputEl().createChild({
2872 o[this.valueField] = 0;
2873 o[this.displayField] = default_text;
2875 this.ios_options.push({
2882 this.store.data.each(function(d, rowIndex){
2886 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2887 html = d.data[this.displayField];
2892 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2893 value = d.data[this.valueField];
2902 if(this.value == d.data[this.valueField]){
2903 option['selected'] = true;
2906 var opt = this.inputEl().createChild(option);
2908 this.ios_options.push({
2915 this.inputEl().on('change', function(){
2916 this.fireEvent('select', this);
2921 clearIOSView: function()
2923 this.inputEl().dom.innerHTML = '';
2925 this.ios_options = [];
2928 setIOSValue: function(v)
2932 if(!this.ios_options){
2936 Roo.each(this.ios_options, function(opts){
2938 opts.el.dom.removeAttribute('selected');
2940 if(opts.data[this.valueField] != v){
2944 opts.el.dom.setAttribute('selected', true);
2950 * @cfg {Boolean} grow
2954 * @cfg {Number} growMin
2958 * @cfg {Number} growMax
2967 Roo.apply(Roo.bootstrap.form.ComboBox, {
2971 cls: 'modal-header',
2993 cls: 'list-group-item',
2997 cls: 'roo-combobox-list-group-item-value'
3001 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
3015 listItemCheckbox : {
3017 cls: 'list-group-item',
3021 cls: 'roo-combobox-list-group-item-value'
3025 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
3041 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
3046 cls: 'modal-footer',
3054 cls: 'col-xs-6 text-left',
3057 cls: 'btn btn-danger roo-touch-view-cancel',
3063 cls: 'col-xs-6 text-right',
3066 cls: 'btn btn-success roo-touch-view-ok',
3077 Roo.apply(Roo.bootstrap.form.ComboBox, {
3079 touchViewTemplate : {
3081 cls: 'modal fade roo-combobox-touch-view',
3085 cls: 'modal-dialog',
3086 style : 'position:fixed', // we have to fix position....
3090 cls: 'modal-content',
3092 Roo.bootstrap.form.ComboBox.header,
3093 Roo.bootstrap.form.ComboBox.body,
3094 Roo.bootstrap.form.ComboBox.footer