7 * @class Roo.bootstrap.ComboBox
8 * @extends Roo.bootstrap.TriggerField
9 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
10 * @cfg {Boolean} append (true|false) default false
11 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
13 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
14 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
15 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
16 * @cfg {Boolean} animate default true
17 * @cfg {Boolean} emptyResultText only for touch device
18 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
20 * Create a new ComboBox.
21 * @param {Object} config Configuration options
23 Roo.bootstrap.ComboBox = function(config){
24 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
28 * Fires when the dropdown list is expanded
29 * @param {Roo.bootstrap.ComboBox} combo This combo box
34 * Fires when the dropdown list is collapsed
35 * @param {Roo.bootstrap.ComboBox} combo This combo box
40 * Fires before a list item is selected. Return false to cancel the selection.
41 * @param {Roo.bootstrap.ComboBox} combo This combo box
42 * @param {Roo.data.Record} record The data record returned from the underlying store
43 * @param {Number} index The index of the selected item in the dropdown list
45 'beforeselect' : true,
48 * Fires when a list item is selected
49 * @param {Roo.bootstrap.ComboBox} combo This combo box
50 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
51 * @param {Number} index The index of the selected item in the dropdown list
56 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
57 * The event object passed has these properties:
58 * @param {Roo.bootstrap.ComboBox} combo This combo box
59 * @param {String} query The query
60 * @param {Boolean} forceAll true to force "all" query
61 * @param {Boolean} cancel true to cancel the query
62 * @param {Object} e The query event object
67 * Fires when the 'add' icon is pressed (add a listener to enable add button)
68 * @param {Roo.bootstrap.ComboBox} combo This combo box
73 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
74 * @param {Roo.bootstrap.ComboBox} combo This combo box
75 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
80 * Fires when the remove value from the combobox array
81 * @param {Roo.bootstrap.ComboBox} combo This combo box
86 * Fires when the remove value from the combobox array
87 * @param {Roo.bootstrap.ComboBox} combo This combo box
91 * @event specialfilter
92 * Fires when specialfilter
93 * @param {Roo.bootstrap.ComboBox} combo This combo box
95 'specialfilter' : true,
98 * Fires when tick the element
99 * @param {Roo.bootstrap.ComboBox} combo This combo box
103 * @event touchviewdisplay
104 * Fires when touch view require special display (default is using displayField)
105 * @param {Roo.bootstrap.ComboBox} combo This combo box
106 * @param {Object} cfg set html .
108 'touchviewdisplay' : true
115 this.selectedIndex = -1;
116 if(this.mode == 'local'){
117 if(config.queryDelay === undefined){
118 this.queryDelay = 10;
120 if(config.minChars === undefined){
126 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
129 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
130 * rendering into an Roo.Editor, defaults to false)
133 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
134 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
137 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
140 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
141 * the dropdown list (defaults to undefined, with no header element)
145 * @cfg {String/Roo.Template} tpl The template to use to render the output
149 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
151 listWidth: undefined,
153 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
154 * mode = 'remote' or 'text' if mode = 'local')
156 displayField: undefined,
159 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
160 * mode = 'remote' or 'value' if mode = 'local').
161 * Note: use of a valueField requires the user make a selection
162 * in order for a value to be mapped.
164 valueField: undefined,
166 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
171 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
172 * field's data value (defaults to the underlying DOM element's name)
174 hiddenName: undefined,
176 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
180 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
182 selectedClass: 'active',
185 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
189 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
190 * anchor positions (defaults to 'tl-bl')
194 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
198 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
199 * query specified by the allQuery config option (defaults to 'query')
201 triggerAction: 'query',
203 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
204 * (defaults to 4, does not apply if editable = false)
208 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
209 * delay (typeAheadDelay) if it matches a known value (defaults to false)
213 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
214 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
218 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
219 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
223 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
224 * when editable = true (defaults to false)
228 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
232 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
233 * when mode = 'remote' (defaults to 'Loading...')
235 loadingText: 'Loading...',
237 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
241 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
245 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
246 * traditional select (defaults to true)
250 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
254 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
258 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
259 * listWidth has a higher value)
263 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
264 * allow the user to set arbitrary text into the field (defaults to false)
266 forceSelection:false,
268 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
269 * if typeAhead = true (defaults to 250)
271 typeAheadDelay : 250,
273 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
274 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
276 valueNotFoundText : undefined,
278 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
283 * @cfg {Boolean} disableClear Disable showing of clear button.
285 disableClear : false,
287 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
292 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
297 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
299 invalidClass : "has-warning",
302 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
304 validClass : "has-success",
307 * @cfg {Boolean} specialFilter (true|false) special filter default false
309 specialFilter : false,
312 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
314 mobileTouchView : true,
317 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
319 useNativeIOS : false,
333 btnPosition : 'right',
335 showToggleBtn : true,
337 emptyResultText: 'Empty',
338 triggerText : 'Select',
340 // element that contains real text value.. (when hidden is used..)
342 getAutoCreate : function()
347 * Render classic select for iso
350 if(Roo.isIOS && this.useNativeIOS){
351 cfg = this.getAutoCreateNativeIOS();
359 if(Roo.isTouch && this.mobileTouchView){
360 cfg = this.getAutoCreateTouchView();
368 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
373 * ComboBox with tickable selections
376 var align = this.labelAlign || this.parentLabelAlign();
379 cls : 'form-group roo-combobox-tickable' //input-group
382 var btn_text_select = '';
383 var btn_text_done = '';
384 var btn_text_cancel = '';
386 if (this.btn_text_show) {
387 btn_text_select = 'Select';
388 btn_text_done = 'Done';
389 btn_text_cancel = 'Cancel';
394 cls : 'tickable-buttons',
399 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
400 //html : this.triggerText
401 html: btn_text_select
407 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
415 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
417 html: btn_text_cancel
425 cls: 'roo-select2-search-field-input'
431 Roo.each(buttons.cn, function(c){
433 c.cls += ' btn-' + _this.size;
436 if (_this.disabled) {
447 cls: 'form-hidden-field'
451 cls: 'roo-select2-choices',
455 cls: 'roo-select2-search-field',
467 cls: 'roo-select2-container input-group roo-select2-container-multi',
472 // cls: 'typeahead typeahead-long dropdown-menu',
473 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
478 if(this.hasFeedback && !this.allowBlank){
482 cls: 'glyphicon form-control-feedback'
485 combobox.cn.push(feedback);
488 if (align ==='left' && this.fieldLabel.length && this.labelWidth) {
490 // Roo.log("left and has label");
494 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
495 tooltip : 'This field is required'
500 cls : 'control-label col-sm-' + this.labelWidth,
501 html : this.fieldLabel
505 cls : "col-sm-" + (12 - this.labelWidth),
513 if(this.indicatorpos == 'right'){
519 cls : 'control-label col-sm-' + this.labelWidth,
520 html : this.fieldLabel
525 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
526 tooltip : 'This field is required'
529 cls : "col-sm-" + (12 - this.labelWidth),
540 } else if ( this.fieldLabel.length) {
541 // Roo.log(" label");
545 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
546 tooltip : 'This field is required'
550 //cls : 'input-group-addon',
551 html : this.fieldLabel
559 if(this.indicatorpos == 'right'){
564 //cls : 'input-group-addon',
565 html : this.fieldLabel
571 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
572 tooltip : 'This field is required'
583 // Roo.log(" no label && no align");
590 ['xs','sm','md','lg'].map(function(size){
591 if (settings[size]) {
592 cfg.cls += ' col-' + size + '-' + settings[size];
600 _initEventsCalled : false,
603 initEvents: function()
605 if (this._initEventsCalled) { // as we call render... prevent looping...
608 this._initEventsCalled = true;
611 throw "can not find store for combo";
614 this.store = Roo.factory(this.store, Roo.data);
616 // if we are building from html. then this element is so complex, that we can not really
617 // use the rendered HTML.
618 // so we have to trash and replace the previous code.
619 if (Roo.XComponent.build_from_html) {
621 // remove this element....
622 var e = this.el.dom, k=0;
623 while (e ) { e = e.previousSibling; ++k;}
628 this.rendered = false;
630 this.render(this.parent().getChildContainer(true), k);
636 if(Roo.isIOS && this.useNativeIOS){
645 if(Roo.isTouch && this.mobileTouchView){
646 this.initTouchView();
651 this.initTickableEvents();
655 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
659 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
661 this.hiddenField.dom.value =
662 this.hiddenValue !== undefined ? this.hiddenValue :
663 this.value !== undefined ? this.value : '';
665 // prevent input submission
666 this.el.dom.removeAttribute('name');
667 this.hiddenField.dom.setAttribute('name', this.hiddenName);
672 // this.el.dom.setAttribute('autocomplete', 'off');
675 var cls = 'x-combo-list';
677 //this.list = new Roo.Layer({
678 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
684 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
685 _this.list.setWidth(lw);
688 this.list.on('mouseover', this.onViewOver, this);
689 this.list.on('mousemove', this.onViewMove, this);
691 this.list.on('scroll', this.onViewScroll, this);
694 this.list.swallowEvent('mousewheel');
695 this.assetHeight = 0;
698 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
699 this.assetHeight += this.header.getHeight();
702 this.innerList = this.list.createChild({cls:cls+'-inner'});
703 this.innerList.on('mouseover', this.onViewOver, this);
704 this.innerList.on('mousemove', this.onViewMove, this);
705 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
707 if(this.allowBlank && !this.pageSize && !this.disableClear){
708 this.footer = this.list.createChild({cls:cls+'-ft'});
709 this.pageTb = new Roo.Toolbar(this.footer);
713 this.footer = this.list.createChild({cls:cls+'-ft'});
714 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
715 {pageSize: this.pageSize});
719 if (this.pageTb && this.allowBlank && !this.disableClear) {
721 this.pageTb.add(new Roo.Toolbar.Fill(), {
722 cls: 'x-btn-icon x-btn-clear',
728 _this.onSelect(false, -1);
733 this.assetHeight += this.footer.getHeight();
738 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
741 this.view = new Roo.View(this.list, this.tpl, {
742 singleSelect:true, store: this.store, selectedClass: this.selectedClass
744 //this.view.wrapEl.setDisplayed(false);
745 this.view.on('click', this.onViewClick, this);
749 this.store.on('beforeload', this.onBeforeLoad, this);
750 this.store.on('load', this.onLoad, this);
751 this.store.on('loadexception', this.onLoadException, this);
754 this.resizer = new Roo.Resizable(this.list, {
755 pinned:true, handles:'se'
757 this.resizer.on('resize', function(r, w, h){
758 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
760 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
761 this.restrictHeight();
763 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
767 this.editable = true;
768 this.setEditable(false);
773 if (typeof(this.events.add.listeners) != 'undefined') {
775 this.addicon = this.wrap.createChild(
776 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
778 this.addicon.on('click', function(e) {
779 this.fireEvent('add', this);
782 if (typeof(this.events.edit.listeners) != 'undefined') {
784 this.editicon = this.wrap.createChild(
785 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
787 this.editicon.setStyle('margin-left', '40px');
789 this.editicon.on('click', function(e) {
791 // we fire even if inothing is selected..
792 this.fireEvent('edit', this, this.lastData );
798 this.keyNav = new Roo.KeyNav(this.inputEl(), {
800 this.inKeyMode = true;
804 "down" : function(e){
805 if(!this.isExpanded()){
806 this.onTriggerClick();
808 this.inKeyMode = true;
813 "enter" : function(e){
814 // this.onViewClick();
818 if(this.fireEvent("specialkey", this, e)){
819 this.onViewClick(false);
832 if(this.fireEvent("specialkey", this, e)){
833 this.onViewClick(false);
841 doRelay : function(foo, bar, hname){
842 if(hname == 'down' || this.scope.isExpanded()){
843 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
852 this.queryDelay = Math.max(this.queryDelay || 10,
853 this.mode == 'local' ? 10 : 250);
856 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
859 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
861 if(this.editable !== false){
862 this.inputEl().on("keyup", this.onKeyUp, this);
864 if(this.forceSelection){
865 this.inputEl().on('blur', this.doForce, this);
869 this.choices = this.el.select('ul.roo-select2-choices', true).first();
870 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
874 initTickableEvents: function()
880 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
882 this.hiddenField.dom.value =
883 this.hiddenValue !== undefined ? this.hiddenValue :
884 this.value !== undefined ? this.value : '';
886 // prevent input submission
887 this.el.dom.removeAttribute('name');
888 this.hiddenField.dom.setAttribute('name', this.hiddenName);
893 // this.list = this.el.select('ul.dropdown-menu',true).first();
895 this.choices = this.el.select('ul.roo-select2-choices', true).first();
896 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
897 if(this.triggerList){
898 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
901 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
902 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
904 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
905 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
907 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
908 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
910 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
911 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
912 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
915 this.cancelBtn.hide();
920 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
921 _this.list.setWidth(lw);
924 this.list.on('mouseover', this.onViewOver, this);
925 this.list.on('mousemove', this.onViewMove, this);
927 this.list.on('scroll', this.onViewScroll, this);
930 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></li>';
933 this.view = new Roo.View(this.list, this.tpl, {
934 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
937 //this.view.wrapEl.setDisplayed(false);
938 this.view.on('click', this.onViewClick, this);
942 this.store.on('beforeload', this.onBeforeLoad, this);
943 this.store.on('load', this.onLoad, this);
944 this.store.on('loadexception', this.onLoadException, this);
947 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
949 this.inKeyMode = true;
953 "down" : function(e){
954 this.inKeyMode = true;
958 "enter" : function(e){
959 if(this.fireEvent("specialkey", this, e)){
960 this.onViewClick(false);
967 this.onTickableFooterButtonClick(e, false, false);
971 this.fireEvent("specialkey", this, e);
973 this.onTickableFooterButtonClick(e, false, false);
980 doRelay : function(e, fn, key){
981 if(this.scope.isExpanded()){
982 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
991 this.queryDelay = Math.max(this.queryDelay || 10,
992 this.mode == 'local' ? 10 : 250);
995 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
998 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1001 if(this.editable !== false){
1002 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1007 onDestroy : function(){
1009 this.view.setStore(null);
1010 this.view.el.removeAllListeners();
1011 this.view.el.remove();
1012 this.view.purgeListeners();
1015 this.list.dom.innerHTML = '';
1019 this.store.un('beforeload', this.onBeforeLoad, this);
1020 this.store.un('load', this.onLoad, this);
1021 this.store.un('loadexception', this.onLoadException, this);
1023 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1027 fireKey : function(e){
1028 if(e.isNavKeyPress() && !this.list.isVisible()){
1029 this.fireEvent("specialkey", this, e);
1034 onResize: function(w, h){
1035 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1037 // if(typeof w != 'number'){
1038 // // we do not handle it!?!?
1041 // var tw = this.trigger.getWidth();
1042 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1043 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1045 // this.inputEl().setWidth( this.adjustWidth('input', x));
1047 // //this.trigger.setStyle('left', x+'px');
1049 // if(this.list && this.listWidth === undefined){
1050 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1051 // this.list.setWidth(lw);
1052 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1060 * Allow or prevent the user from directly editing the field text. If false is passed,
1061 * the user will only be able to select from the items defined in the dropdown list. This method
1062 * is the runtime equivalent of setting the 'editable' config option at config time.
1063 * @param {Boolean} value True to allow the user to directly edit the field text
1065 setEditable : function(value){
1066 if(value == this.editable){
1069 this.editable = value;
1071 this.inputEl().dom.setAttribute('readOnly', true);
1072 this.inputEl().on('mousedown', this.onTriggerClick, this);
1073 this.inputEl().addClass('x-combo-noedit');
1075 this.inputEl().dom.setAttribute('readOnly', false);
1076 this.inputEl().un('mousedown', this.onTriggerClick, this);
1077 this.inputEl().removeClass('x-combo-noedit');
1083 onBeforeLoad : function(combo,opts){
1088 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1090 this.restrictHeight();
1091 this.selectedIndex = -1;
1095 onLoad : function(){
1097 this.hasQuery = false;
1103 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1104 this.loading.hide();
1107 if(this.store.getCount() > 0){
1109 this.restrictHeight();
1110 if(this.lastQuery == this.allQuery){
1111 if(this.editable && !this.tickable){
1112 this.inputEl().dom.select();
1116 !this.selectByValue(this.value, true) &&
1119 !this.store.lastOptions ||
1120 typeof(this.store.lastOptions.add) == 'undefined' ||
1121 this.store.lastOptions.add != true
1124 this.select(0, true);
1130 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1131 this.taTask.delay(this.typeAheadDelay);
1135 this.onEmptyResults();
1141 onLoadException : function()
1143 this.hasQuery = false;
1145 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1146 this.loading.hide();
1149 if(this.tickable && this.editable){
1154 // only causes errors at present
1155 //Roo.log(this.store.reader.jsonData);
1156 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1158 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1164 onTypeAhead : function(){
1165 if(this.store.getCount() > 0){
1166 var r = this.store.getAt(0);
1167 var newValue = r.data[this.displayField];
1168 var len = newValue.length;
1169 var selStart = this.getRawValue().length;
1171 if(selStart != len){
1172 this.setRawValue(newValue);
1173 this.selectText(selStart, newValue.length);
1179 onSelect : function(record, index){
1181 if(this.fireEvent('beforeselect', this, record, index) !== false){
1183 this.setFromData(index > -1 ? record.data : false);
1186 this.fireEvent('select', this, record, index);
1191 * Returns the currently selected field value or empty string if no value is set.
1192 * @return {String} value The selected value
1194 getValue : function()
1196 if(Roo.isIOS && this.useNativeIOS){
1197 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1201 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1204 if(this.valueField){
1205 return typeof this.value != 'undefined' ? this.value : '';
1207 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1211 getRawValue : function()
1213 if(Roo.isIOS && this.useNativeIOS){
1214 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1217 var v = this.inputEl().getValue();
1223 * Clears any text/value currently set in the field
1225 clearValue : function(){
1227 if(this.hiddenField){
1228 this.hiddenField.dom.value = '';
1231 this.setRawValue('');
1232 this.lastSelectionText = '';
1233 this.lastData = false;
1235 var close = this.closeTriggerEl();
1246 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1247 * will be displayed in the field. If the value does not match the data value of an existing item,
1248 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1249 * Otherwise the field will be blank (although the value will still be set).
1250 * @param {String} value The value to match
1252 setValue : function(v)
1254 if(Roo.isIOS && this.useNativeIOS){
1255 this.setIOSValue(v);
1265 if(this.valueField){
1266 var r = this.findRecord(this.valueField, v);
1268 text = r.data[this.displayField];
1269 }else if(this.valueNotFoundText !== undefined){
1270 text = this.valueNotFoundText;
1273 this.lastSelectionText = text;
1274 if(this.hiddenField){
1275 this.hiddenField.dom.value = v;
1277 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1280 var close = this.closeTriggerEl();
1283 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1289 * @property {Object} the last set data for the element
1294 * Sets the value of the field based on a object which is related to the record format for the store.
1295 * @param {Object} value the value to set as. or false on reset?
1297 setFromData : function(o){
1304 var dv = ''; // display value
1305 var vv = ''; // value value..
1307 if (this.displayField) {
1308 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1310 // this is an error condition!!!
1311 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1314 if(this.valueField){
1315 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1318 var close = this.closeTriggerEl();
1321 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1324 if(this.hiddenField){
1325 this.hiddenField.dom.value = vv;
1327 this.lastSelectionText = dv;
1328 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1332 // no hidden field.. - we store the value in 'value', but still display
1333 // display field!!!!
1334 this.lastSelectionText = dv;
1335 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1343 // overridden so that last data is reset..
1350 this.setValue(this.originalValue);
1351 //this.clearInvalid();
1352 this.lastData = false;
1354 this.view.clearSelections();
1360 findRecord : function(prop, value){
1362 if(this.store.getCount() > 0){
1363 this.store.each(function(r){
1364 if(r.data[prop] == value){
1376 // returns hidden if it's set..
1377 if (!this.rendered) {return ''};
1378 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1382 onViewMove : function(e, t){
1383 this.inKeyMode = false;
1387 onViewOver : function(e, t){
1388 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1391 var item = this.view.findItemFromChild(t);
1394 var index = this.view.indexOf(item);
1395 this.select(index, false);
1400 onViewClick : function(view, doFocus, el, e)
1402 var index = this.view.getSelectedIndexes()[0];
1404 var r = this.store.getAt(index);
1408 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1415 Roo.each(this.tickItems, function(v,k){
1417 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1419 _this.tickItems.splice(k, 1);
1421 if(typeof(e) == 'undefined' && view == false){
1422 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1434 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1435 this.tickItems.push(r.data);
1438 if(typeof(e) == 'undefined' && view == false){
1439 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1446 this.onSelect(r, index);
1448 if(doFocus !== false && !this.blockFocus){
1449 this.inputEl().focus();
1454 restrictHeight : function(){
1455 //this.innerList.dom.style.height = '';
1456 //var inner = this.innerList.dom;
1457 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1458 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1459 //this.list.beginUpdate();
1460 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1461 this.list.alignTo(this.inputEl(), this.listAlign);
1462 this.list.alignTo(this.inputEl(), this.listAlign);
1463 //this.list.endUpdate();
1467 onEmptyResults : function(){
1469 if(this.tickable && this.editable){
1470 this.restrictHeight();
1478 * Returns true if the dropdown list is expanded, else false.
1480 isExpanded : function(){
1481 return this.list.isVisible();
1485 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1486 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1487 * @param {String} value The data value of the item to select
1488 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1489 * selected item if it is not currently in view (defaults to true)
1490 * @return {Boolean} True if the value matched an item in the list, else false
1492 selectByValue : function(v, scrollIntoView){
1493 if(v !== undefined && v !== null){
1494 var r = this.findRecord(this.valueField || this.displayField, v);
1496 this.select(this.store.indexOf(r), scrollIntoView);
1504 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1505 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1506 * @param {Number} index The zero-based index of the list item to select
1507 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1508 * selected item if it is not currently in view (defaults to true)
1510 select : function(index, scrollIntoView){
1511 this.selectedIndex = index;
1512 this.view.select(index);
1513 if(scrollIntoView !== false){
1514 var el = this.view.getNode(index);
1516 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1519 this.list.scrollChildIntoView(el, false);
1525 selectNext : function(){
1526 var ct = this.store.getCount();
1528 if(this.selectedIndex == -1){
1530 }else if(this.selectedIndex < ct-1){
1531 this.select(this.selectedIndex+1);
1537 selectPrev : function(){
1538 var ct = this.store.getCount();
1540 if(this.selectedIndex == -1){
1542 }else if(this.selectedIndex != 0){
1543 this.select(this.selectedIndex-1);
1549 onKeyUp : function(e){
1550 if(this.editable !== false && !e.isSpecialKey()){
1551 this.lastKey = e.getKey();
1552 this.dqTask.delay(this.queryDelay);
1557 validateBlur : function(){
1558 return !this.list || !this.list.isVisible();
1562 initQuery : function(){
1564 var v = this.getRawValue();
1566 if(this.tickable && this.editable){
1567 v = this.tickableInputEl().getValue();
1574 doForce : function(){
1575 if(this.inputEl().dom.value.length > 0){
1576 this.inputEl().dom.value =
1577 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1583 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1584 * query allowing the query action to be canceled if needed.
1585 * @param {String} query The SQL query to execute
1586 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1587 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1588 * saved in the current store (defaults to false)
1590 doQuery : function(q, forceAll){
1592 if(q === undefined || q === null){
1601 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1606 forceAll = qe.forceAll;
1607 if(forceAll === true || (q.length >= this.minChars)){
1609 this.hasQuery = true;
1611 if(this.lastQuery != q || this.alwaysQuery){
1613 if(this.mode == 'local'){
1614 this.selectedIndex = -1;
1616 this.store.clearFilter();
1619 if(this.specialFilter){
1620 this.fireEvent('specialfilter', this);
1625 this.store.filter(this.displayField, q);
1628 this.store.fireEvent("datachanged", this.store);
1635 this.store.baseParams[this.queryParam] = q;
1637 var options = {params : this.getParams(q)};
1641 options.params.start = this.page * this.pageSize;
1644 this.store.load(options);
1647 * this code will make the page width larger, at the beginning, the list not align correctly,
1648 * we should expand the list on onLoad
1654 this.selectedIndex = -1;
1659 this.loadNext = false;
1663 getParams : function(q){
1665 //p[this.queryParam] = q;
1669 p.limit = this.pageSize;
1675 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1677 collapse : function(){
1678 if(!this.isExpanded()){
1684 this.hasFocus = false;
1688 this.cancelBtn.hide();
1689 this.trigger.show();
1692 this.tickableInputEl().dom.value = '';
1693 this.tickableInputEl().blur();
1698 Roo.get(document).un('mousedown', this.collapseIf, this);
1699 Roo.get(document).un('mousewheel', this.collapseIf, this);
1700 if (!this.editable) {
1701 Roo.get(document).un('keydown', this.listKeyPress, this);
1703 this.fireEvent('collapse', this);
1709 collapseIf : function(e){
1710 var in_combo = e.within(this.el);
1711 var in_list = e.within(this.list);
1712 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1714 if (in_combo || in_list || is_list) {
1715 //e.stopPropagation();
1720 this.onTickableFooterButtonClick(e, false, false);
1728 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1730 expand : function(){
1732 if(this.isExpanded() || !this.hasFocus){
1736 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1737 this.list.setWidth(lw);
1743 this.restrictHeight();
1747 this.tickItems = Roo.apply([], this.item);
1750 this.cancelBtn.show();
1751 this.trigger.hide();
1754 this.tickableInputEl().focus();
1759 Roo.get(document).on('mousedown', this.collapseIf, this);
1760 Roo.get(document).on('mousewheel', this.collapseIf, this);
1761 if (!this.editable) {
1762 Roo.get(document).on('keydown', this.listKeyPress, this);
1765 this.fireEvent('expand', this);
1769 // Implements the default empty TriggerField.onTriggerClick function
1770 onTriggerClick : function(e)
1772 Roo.log('trigger click');
1774 if(this.disabled || !this.triggerList){
1779 this.loadNext = false;
1781 if(this.isExpanded()){
1783 if (!this.blockFocus) {
1784 this.inputEl().focus();
1788 this.hasFocus = true;
1789 if(this.triggerAction == 'all') {
1790 this.doQuery(this.allQuery, true);
1792 this.doQuery(this.getRawValue());
1794 if (!this.blockFocus) {
1795 this.inputEl().focus();
1800 onTickableTriggerClick : function(e)
1807 this.loadNext = false;
1808 this.hasFocus = true;
1810 if(this.triggerAction == 'all') {
1811 this.doQuery(this.allQuery, true);
1813 this.doQuery(this.getRawValue());
1817 onSearchFieldClick : function(e)
1819 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1820 this.onTickableFooterButtonClick(e, false, false);
1824 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1829 this.loadNext = false;
1830 this.hasFocus = true;
1832 if(this.triggerAction == 'all') {
1833 this.doQuery(this.allQuery, true);
1835 this.doQuery(this.getRawValue());
1839 listKeyPress : function(e)
1841 //Roo.log('listkeypress');
1842 // scroll to first matching element based on key pres..
1843 if (e.isSpecialKey()) {
1846 var k = String.fromCharCode(e.getKey()).toUpperCase();
1849 var csel = this.view.getSelectedNodes();
1850 var cselitem = false;
1852 var ix = this.view.indexOf(csel[0]);
1853 cselitem = this.store.getAt(ix);
1854 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1860 this.store.each(function(v) {
1862 // start at existing selection.
1863 if (cselitem.id == v.id) {
1869 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1870 match = this.store.indexOf(v);
1876 if (match === false) {
1877 return true; // no more action?
1880 this.view.select(match);
1881 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1882 sn.scrollIntoView(sn.dom.parentNode, false);
1885 onViewScroll : function(e, t){
1887 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){
1891 this.hasQuery = true;
1893 this.loading = this.list.select('.loading', true).first();
1895 if(this.loading === null){
1896 this.list.createChild({
1898 cls: 'loading roo-select2-more-results roo-select2-active',
1899 html: 'Loading more results...'
1902 this.loading = this.list.select('.loading', true).first();
1904 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1906 this.loading.hide();
1909 this.loading.show();
1914 this.loadNext = true;
1916 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1921 addItem : function(o)
1923 var dv = ''; // display value
1925 if (this.displayField) {
1926 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1928 // this is an error condition!!!
1929 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1936 var choice = this.choices.createChild({
1938 cls: 'roo-select2-search-choice',
1947 cls: 'roo-select2-search-choice-close',
1952 }, this.searchField);
1954 var close = choice.select('a.roo-select2-search-choice-close', true).first();
1956 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1964 this.inputEl().dom.value = '';
1969 onRemoveItem : function(e, _self, o)
1973 this.lastItem = Roo.apply([], this.item);
1975 var index = this.item.indexOf(o.data) * 1;
1978 Roo.log('not this item?!');
1982 this.item.splice(index, 1);
1987 this.fireEvent('remove', this, e);
1993 syncValue : function()
1995 if(!this.item.length){
2002 Roo.each(this.item, function(i){
2003 if(_this.valueField){
2004 value.push(i[_this.valueField]);
2011 this.value = value.join(',');
2013 if(this.hiddenField){
2014 this.hiddenField.dom.value = this.value;
2017 this.store.fireEvent("datachanged", this.store);
2022 clearItem : function()
2030 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2038 if(this.tickable && !Roo.isTouch){
2039 this.view.refresh();
2043 inputEl: function ()
2045 if(Roo.isIOS && this.useNativeIOS){
2046 return this.el.select('select.roo-ios-select', true).first();
2049 if(Roo.isTouch && this.mobileTouchView){
2050 return this.el.select('input.form-control',true).first();
2054 return this.searchField;
2057 return this.el.select('input.form-control',true).first();
2060 onTickableFooterButtonClick : function(e, btn, el)
2064 this.lastItem = Roo.apply([], this.item);
2066 if(btn && btn.name == 'cancel'){
2067 this.tickItems = Roo.apply([], this.item);
2076 Roo.each(this.tickItems, function(o){
2084 validate : function()
2086 var v = this.getRawValue();
2089 v = this.getValue();
2092 if(this.disabled || this.allowBlank || v.length){
2101 tickableInputEl : function()
2103 if(!this.tickable || !this.editable){
2104 return this.inputEl();
2107 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2111 getAutoCreateTouchView : function()
2116 cls: 'form-group' //input-group
2122 type : this.inputType,
2123 cls : 'form-control x-combo-noedit',
2124 autocomplete: 'new-password',
2125 placeholder : this.placeholder || '',
2130 input.name = this.name;
2134 input.cls += ' input-' + this.size;
2137 if (this.disabled) {
2138 input.disabled = true;
2149 inputblock.cls += ' input-group';
2151 inputblock.cn.unshift({
2153 cls : 'input-group-addon',
2158 if(this.removable && !this.multiple){
2159 inputblock.cls += ' roo-removable';
2161 inputblock.cn.push({
2164 cls : 'roo-combo-removable-btn close'
2168 if(this.hasFeedback && !this.allowBlank){
2170 inputblock.cls += ' has-feedback';
2172 inputblock.cn.push({
2174 cls: 'glyphicon form-control-feedback'
2181 inputblock.cls += (this.before) ? '' : ' input-group';
2183 inputblock.cn.push({
2185 cls : 'input-group-addon',
2196 cls: 'form-hidden-field'
2210 cls: 'form-hidden-field'
2214 cls: 'roo-select2-choices',
2218 cls: 'roo-select2-search-field',
2231 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2237 if(!this.multiple && this.showToggleBtn){
2244 if (this.caret != false) {
2247 cls: 'fa fa-' + this.caret
2254 cls : 'input-group-addon btn dropdown-toggle',
2259 cls: 'combobox-clear',
2273 combobox.cls += ' roo-select2-container-multi';
2276 var align = this.labelAlign || this.parentLabelAlign();
2280 if(this.fieldLabel.length && this.labelWidth){
2282 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2283 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2288 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2289 tooltip : 'This field is required'
2293 cls : 'control-label ' + lw,
2294 html : this.fieldLabel
2305 if(this.indicatorpos == 'right'){
2309 cls : 'control-label ' + lw,
2310 html : this.fieldLabel
2315 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2316 tooltip : 'This field is required'
2328 var settings = this;
2330 ['xs','sm','md','lg'].map(function(size){
2331 if (settings[size]) {
2332 cfg.cls += ' col-' + size + '-' + settings[size];
2339 initTouchView : function()
2341 this.renderTouchView();
2343 this.touchViewEl.on('scroll', function(){
2344 this.el.dom.scrollTop = 0;
2347 this.originalValue = this.getValue();
2349 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2351 this.inputEl().on("click", this.showTouchView, this);
2352 if (this.triggerEl) {
2353 this.triggerEl.on("click", this.showTouchView, this);
2357 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2358 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2360 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2362 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2363 this.store.on('load', this.onTouchViewLoad, this);
2364 this.store.on('loadexception', this.onTouchViewLoadException, this);
2366 if(this.hiddenName){
2368 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2370 this.hiddenField.dom.value =
2371 this.hiddenValue !== undefined ? this.hiddenValue :
2372 this.value !== undefined ? this.value : '';
2374 this.el.dom.removeAttribute('name');
2375 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2379 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2380 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2383 if(this.removable && !this.multiple){
2384 var close = this.closeTriggerEl();
2386 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2387 close.on('click', this.removeBtnClick, this, close);
2391 * fix the bug in Safari iOS8
2393 this.inputEl().on("focus", function(e){
2394 document.activeElement.blur();
2402 renderTouchView : function()
2404 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2405 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2407 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2408 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2410 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2411 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2412 this.touchViewBodyEl.setStyle('overflow', 'auto');
2414 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2415 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2417 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2418 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2422 showTouchView : function()
2428 this.touchViewHeaderEl.hide();
2430 if(this.modalTitle.length){
2431 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2432 this.touchViewHeaderEl.show();
2435 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2436 this.touchViewEl.show();
2438 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2439 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2440 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2442 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2444 if(this.modalTitle.length){
2445 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2448 this.touchViewBodyEl.setHeight(bodyHeight);
2452 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2454 this.touchViewEl.addClass('in');
2457 this.doTouchViewQuery();
2461 hideTouchView : function()
2463 this.touchViewEl.removeClass('in');
2467 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2469 this.touchViewEl.setStyle('display', 'none');
2474 setTouchViewValue : function()
2481 Roo.each(this.tickItems, function(o){
2486 this.hideTouchView();
2489 doTouchViewQuery : function()
2498 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2502 if(!this.alwaysQuery || this.mode == 'local'){
2503 this.onTouchViewLoad();
2510 onTouchViewBeforeLoad : function(combo,opts)
2516 onTouchViewLoad : function()
2518 if(this.store.getCount() < 1){
2519 this.onTouchViewEmptyResults();
2523 this.clearTouchView();
2525 var rawValue = this.getRawValue();
2527 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2529 this.tickItems = [];
2531 this.store.data.each(function(d, rowIndex){
2532 var row = this.touchViewListGroup.createChild(template);
2534 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2535 row.addClass(d.data.cls);
2538 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2541 html : d.data[this.displayField]
2544 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2545 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2548 row.removeClass('selected');
2549 if(!this.multiple && this.valueField &&
2550 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2553 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2554 row.addClass('selected');
2557 if(this.multiple && this.valueField &&
2558 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2562 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2563 this.tickItems.push(d.data);
2566 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2570 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2572 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2574 if(this.modalTitle.length){
2575 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2578 var listHeight = this.touchViewListGroup.getHeight();
2582 if(firstChecked && listHeight > bodyHeight){
2583 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2588 onTouchViewLoadException : function()
2590 this.hideTouchView();
2593 onTouchViewEmptyResults : function()
2595 this.clearTouchView();
2597 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2599 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2603 clearTouchView : function()
2605 this.touchViewListGroup.dom.innerHTML = '';
2608 onTouchViewClick : function(e, el, o)
2613 var rowIndex = o.rowIndex;
2615 var r = this.store.getAt(rowIndex);
2617 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2620 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2621 c.dom.removeAttribute('checked');
2624 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2626 this.setFromData(r.data);
2628 var close = this.closeTriggerEl();
2634 this.hideTouchView();
2636 this.fireEvent('select', this, r, rowIndex);
2641 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2642 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2643 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2647 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2648 this.addItem(r.data);
2649 this.tickItems.push(r.data);
2653 getAutoCreateNativeIOS : function()
2656 cls: 'form-group' //input-group,
2661 cls : 'roo-ios-select'
2665 combobox.name = this.name;
2668 if (this.disabled) {
2669 combobox.disabled = true;
2672 var settings = this;
2674 ['xs','sm','md','lg'].map(function(size){
2675 if (settings[size]) {
2676 cfg.cls += ' col-' + size + '-' + settings[size];
2686 initIOSView : function()
2688 this.store.on('load', this.onIOSViewLoad, this);
2693 onIOSViewLoad : function()
2695 if(this.store.getCount() < 1){
2699 this.clearIOSView();
2701 if(this.allowBlank) {
2703 var default_text = '-- SELECT --';
2705 var opt = this.inputEl().createChild({
2712 o[this.valueField] = 0;
2713 o[this.displayField] = default_text;
2715 this.ios_options.push({
2722 this.store.data.each(function(d, rowIndex){
2726 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2727 html = d.data[this.displayField];
2732 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2733 value = d.data[this.valueField];
2742 if(this.value == d.data[this.valueField]){
2743 option['selected'] = true;
2746 var opt = this.inputEl().createChild(option);
2748 this.ios_options.push({
2755 this.inputEl().on('change', function(){
2756 this.fireEvent('select', this);
2761 clearIOSView: function()
2763 this.inputEl().dom.innerHTML = '';
2765 this.ios_options = [];
2768 setIOSValue: function(v)
2772 if(!this.ios_options){
2776 Roo.each(this.ios_options, function(opts){
2778 opts.el.dom.removeAttribute('selected');
2780 if(opts.data[this.valueField] != v){
2784 opts.el.dom.setAttribute('selected', true);
2790 * @cfg {Boolean} grow
2794 * @cfg {Number} growMin
2798 * @cfg {Number} growMax
2807 Roo.apply(Roo.bootstrap.ComboBox, {
2811 cls: 'modal-header',
2833 cls: 'list-group-item',
2837 cls: 'roo-combobox-list-group-item-value'
2841 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2855 listItemCheckbox : {
2857 cls: 'list-group-item',
2861 cls: 'roo-combobox-list-group-item-value'
2865 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2881 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2886 cls: 'modal-footer',
2894 cls: 'col-xs-6 text-left',
2897 cls: 'btn btn-danger roo-touch-view-cancel',
2903 cls: 'col-xs-6 text-right',
2906 cls: 'btn btn-success roo-touch-view-ok',
2917 Roo.apply(Roo.bootstrap.ComboBox, {
2919 touchViewTemplate : {
2921 cls: 'modal fade roo-combobox-touch-view',
2925 cls: 'modal-dialog',
2926 style : 'position:fixed', // we have to fix position....
2930 cls: 'modal-content',
2932 Roo.bootstrap.ComboBox.header,
2933 Roo.bootstrap.ComboBox.body,
2934 Roo.bootstrap.ComboBox.footer