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) {
493 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
494 tooltip : 'This field is required'
499 cls : 'control-label',
500 html : this.fieldLabel
512 var labelCfg = cfg.cn[1];
513 var contentCfg = cfg.cn[2];
516 if(this.indicatorpos == 'right'){
522 cls : 'control-label',
523 html : this.fieldLabel
528 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
529 tooltip : 'This field is required'
540 labelCfg = cfg.cn[0];
544 if(this.labelWidth > 12){
545 labelCfg.style = "width: " + this.labelWidth + 'px';
548 if(this.labelWidth < 13 && this.labelmd == 0){
549 this.labelmd = this.labelWidth;
552 if(this.labellg > 0){
553 labelCfg.cls += ' col-lg-' + this.labellg;
554 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
557 if(this.labelmd > 0){
558 labelCfg.cls += ' col-md-' + this.labelmd;
559 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
562 if(this.labelsm > 0){
563 labelCfg.cls += ' col-sm-' + this.labelsm;
564 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
567 if(this.labelxs > 0){
568 labelCfg.cls += ' col-xs-' + this.labelxs;
569 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
573 } else if ( this.fieldLabel.length) {
574 // Roo.log(" label");
578 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
579 tooltip : 'This field is required'
583 //cls : 'input-group-addon',
584 html : this.fieldLabel
592 if(this.indicatorpos == 'right'){
597 //cls : 'input-group-addon',
598 html : this.fieldLabel
604 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
605 tooltip : 'This field is required'
616 // Roo.log(" no label && no align");
623 ['xs','sm','md','lg'].map(function(size){
624 if (settings[size]) {
625 cfg.cls += ' col-' + size + '-' + settings[size];
633 _initEventsCalled : false,
636 initEvents: function()
638 if (this._initEventsCalled) { // as we call render... prevent looping...
641 this._initEventsCalled = true;
644 throw "can not find store for combo";
647 this.store = Roo.factory(this.store, Roo.data);
649 // if we are building from html. then this element is so complex, that we can not really
650 // use the rendered HTML.
651 // so we have to trash and replace the previous code.
652 if (Roo.XComponent.build_from_html) {
654 // remove this element....
655 var e = this.el.dom, k=0;
656 while (e ) { e = e.previousSibling; ++k;}
661 this.rendered = false;
663 this.render(this.parent().getChildContainer(true), k);
669 if(Roo.isIOS && this.useNativeIOS){
678 if(Roo.isTouch && this.mobileTouchView){
679 this.initTouchView();
684 this.initTickableEvents();
688 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
692 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
694 this.hiddenField.dom.value =
695 this.hiddenValue !== undefined ? this.hiddenValue :
696 this.value !== undefined ? this.value : '';
698 // prevent input submission
699 this.el.dom.removeAttribute('name');
700 this.hiddenField.dom.setAttribute('name', this.hiddenName);
705 // this.el.dom.setAttribute('autocomplete', 'off');
708 var cls = 'x-combo-list';
710 //this.list = new Roo.Layer({
711 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
717 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
718 _this.list.setWidth(lw);
721 this.list.on('mouseover', this.onViewOver, this);
722 this.list.on('mousemove', this.onViewMove, this);
724 this.list.on('scroll', this.onViewScroll, this);
727 this.list.swallowEvent('mousewheel');
728 this.assetHeight = 0;
731 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
732 this.assetHeight += this.header.getHeight();
735 this.innerList = this.list.createChild({cls:cls+'-inner'});
736 this.innerList.on('mouseover', this.onViewOver, this);
737 this.innerList.on('mousemove', this.onViewMove, this);
738 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
740 if(this.allowBlank && !this.pageSize && !this.disableClear){
741 this.footer = this.list.createChild({cls:cls+'-ft'});
742 this.pageTb = new Roo.Toolbar(this.footer);
746 this.footer = this.list.createChild({cls:cls+'-ft'});
747 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
748 {pageSize: this.pageSize});
752 if (this.pageTb && this.allowBlank && !this.disableClear) {
754 this.pageTb.add(new Roo.Toolbar.Fill(), {
755 cls: 'x-btn-icon x-btn-clear',
761 _this.onSelect(false, -1);
766 this.assetHeight += this.footer.getHeight();
771 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
774 this.view = new Roo.View(this.list, this.tpl, {
775 singleSelect:true, store: this.store, selectedClass: this.selectedClass
777 //this.view.wrapEl.setDisplayed(false);
778 this.view.on('click', this.onViewClick, this);
782 this.store.on('beforeload', this.onBeforeLoad, this);
783 this.store.on('load', this.onLoad, this);
784 this.store.on('loadexception', this.onLoadException, this);
787 this.resizer = new Roo.Resizable(this.list, {
788 pinned:true, handles:'se'
790 this.resizer.on('resize', function(r, w, h){
791 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
793 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
794 this.restrictHeight();
796 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
800 this.editable = true;
801 this.setEditable(false);
806 if (typeof(this.events.add.listeners) != 'undefined') {
808 this.addicon = this.wrap.createChild(
809 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
811 this.addicon.on('click', function(e) {
812 this.fireEvent('add', this);
815 if (typeof(this.events.edit.listeners) != 'undefined') {
817 this.editicon = this.wrap.createChild(
818 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
820 this.editicon.setStyle('margin-left', '40px');
822 this.editicon.on('click', function(e) {
824 // we fire even if inothing is selected..
825 this.fireEvent('edit', this, this.lastData );
831 this.keyNav = new Roo.KeyNav(this.inputEl(), {
833 this.inKeyMode = true;
837 "down" : function(e){
838 if(!this.isExpanded()){
839 this.onTriggerClick();
841 this.inKeyMode = true;
846 "enter" : function(e){
847 // this.onViewClick();
851 if(this.fireEvent("specialkey", this, e)){
852 this.onViewClick(false);
865 if(this.fireEvent("specialkey", this, e)){
866 this.onViewClick(false);
874 doRelay : function(foo, bar, hname){
875 if(hname == 'down' || this.scope.isExpanded()){
876 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
885 this.queryDelay = Math.max(this.queryDelay || 10,
886 this.mode == 'local' ? 10 : 250);
889 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
892 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
894 if(this.editable !== false){
895 this.inputEl().on("keyup", this.onKeyUp, this);
897 if(this.forceSelection){
898 this.inputEl().on('blur', this.doForce, this);
902 this.choices = this.el.select('ul.roo-select2-choices', true).first();
903 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
907 initTickableEvents: function()
913 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
915 this.hiddenField.dom.value =
916 this.hiddenValue !== undefined ? this.hiddenValue :
917 this.value !== undefined ? this.value : '';
919 // prevent input submission
920 this.el.dom.removeAttribute('name');
921 this.hiddenField.dom.setAttribute('name', this.hiddenName);
926 // this.list = this.el.select('ul.dropdown-menu',true).first();
928 this.choices = this.el.select('ul.roo-select2-choices', true).first();
929 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
930 if(this.triggerList){
931 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
934 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
935 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
937 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
938 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
940 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
941 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
943 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
944 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
945 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
948 this.cancelBtn.hide();
953 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
954 _this.list.setWidth(lw);
957 this.list.on('mouseover', this.onViewOver, this);
958 this.list.on('mousemove', this.onViewMove, this);
960 this.list.on('scroll', this.onViewScroll, this);
963 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
966 this.view = new Roo.View(this.list, this.tpl, {
967 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
970 //this.view.wrapEl.setDisplayed(false);
971 this.view.on('click', this.onViewClick, this);
975 this.store.on('beforeload', this.onBeforeLoad, this);
976 this.store.on('load', this.onLoad, this);
977 this.store.on('loadexception', this.onLoadException, this);
980 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
982 this.inKeyMode = true;
986 "down" : function(e){
987 this.inKeyMode = true;
991 "enter" : function(e){
992 if(this.fireEvent("specialkey", this, e)){
993 this.onViewClick(false);
1000 this.onTickableFooterButtonClick(e, false, false);
1003 "tab" : function(e){
1004 this.fireEvent("specialkey", this, e);
1006 this.onTickableFooterButtonClick(e, false, false);
1013 doRelay : function(e, fn, key){
1014 if(this.scope.isExpanded()){
1015 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
1024 this.queryDelay = Math.max(this.queryDelay || 10,
1025 this.mode == 'local' ? 10 : 250);
1028 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
1031 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
1034 if(this.editable !== false){
1035 this.tickableInputEl().on("keyup", this.onKeyUp, this);
1040 onDestroy : function(){
1042 this.view.setStore(null);
1043 this.view.el.removeAllListeners();
1044 this.view.el.remove();
1045 this.view.purgeListeners();
1048 this.list.dom.innerHTML = '';
1052 this.store.un('beforeload', this.onBeforeLoad, this);
1053 this.store.un('load', this.onLoad, this);
1054 this.store.un('loadexception', this.onLoadException, this);
1056 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
1060 fireKey : function(e){
1061 if(e.isNavKeyPress() && !this.list.isVisible()){
1062 this.fireEvent("specialkey", this, e);
1067 onResize: function(w, h){
1068 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
1070 // if(typeof w != 'number'){
1071 // // we do not handle it!?!?
1074 // var tw = this.trigger.getWidth();
1075 // // tw += this.addicon ? this.addicon.getWidth() : 0;
1076 // // tw += this.editicon ? this.editicon.getWidth() : 0;
1078 // this.inputEl().setWidth( this.adjustWidth('input', x));
1080 // //this.trigger.setStyle('left', x+'px');
1082 // if(this.list && this.listWidth === undefined){
1083 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
1084 // this.list.setWidth(lw);
1085 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
1093 * Allow or prevent the user from directly editing the field text. If false is passed,
1094 * the user will only be able to select from the items defined in the dropdown list. This method
1095 * is the runtime equivalent of setting the 'editable' config option at config time.
1096 * @param {Boolean} value True to allow the user to directly edit the field text
1098 setEditable : function(value){
1099 if(value == this.editable){
1102 this.editable = value;
1104 this.inputEl().dom.setAttribute('readOnly', true);
1105 this.inputEl().on('mousedown', this.onTriggerClick, this);
1106 this.inputEl().addClass('x-combo-noedit');
1108 this.inputEl().dom.setAttribute('readOnly', false);
1109 this.inputEl().un('mousedown', this.onTriggerClick, this);
1110 this.inputEl().removeClass('x-combo-noedit');
1116 onBeforeLoad : function(combo,opts){
1121 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
1123 this.restrictHeight();
1124 this.selectedIndex = -1;
1128 onLoad : function(){
1130 this.hasQuery = false;
1136 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1137 this.loading.hide();
1140 if(this.store.getCount() > 0){
1142 this.restrictHeight();
1143 if(this.lastQuery == this.allQuery){
1144 if(this.editable && !this.tickable){
1145 this.inputEl().dom.select();
1149 !this.selectByValue(this.value, true) &&
1152 !this.store.lastOptions ||
1153 typeof(this.store.lastOptions.add) == 'undefined' ||
1154 this.store.lastOptions.add != true
1157 this.select(0, true);
1163 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
1164 this.taTask.delay(this.typeAheadDelay);
1168 this.onEmptyResults();
1174 onLoadException : function()
1176 this.hasQuery = false;
1178 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
1179 this.loading.hide();
1182 if(this.tickable && this.editable){
1187 // only causes errors at present
1188 //Roo.log(this.store.reader.jsonData);
1189 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
1191 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
1197 onTypeAhead : function(){
1198 if(this.store.getCount() > 0){
1199 var r = this.store.getAt(0);
1200 var newValue = r.data[this.displayField];
1201 var len = newValue.length;
1202 var selStart = this.getRawValue().length;
1204 if(selStart != len){
1205 this.setRawValue(newValue);
1206 this.selectText(selStart, newValue.length);
1212 onSelect : function(record, index){
1214 if(this.fireEvent('beforeselect', this, record, index) !== false){
1216 this.setFromData(index > -1 ? record.data : false);
1219 this.fireEvent('select', this, record, index);
1224 * Returns the currently selected field value or empty string if no value is set.
1225 * @return {String} value The selected value
1227 getValue : function()
1229 if(Roo.isIOS && this.useNativeIOS){
1230 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
1234 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
1237 if(this.valueField){
1238 return typeof this.value != 'undefined' ? this.value : '';
1240 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
1244 getRawValue : function()
1246 if(Roo.isIOS && this.useNativeIOS){
1247 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
1250 var v = this.inputEl().getValue();
1256 * Clears any text/value currently set in the field
1258 clearValue : function(){
1260 if(this.hiddenField){
1261 this.hiddenField.dom.value = '';
1264 this.setRawValue('');
1265 this.lastSelectionText = '';
1266 this.lastData = false;
1268 var close = this.closeTriggerEl();
1279 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1280 * will be displayed in the field. If the value does not match the data value of an existing item,
1281 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1282 * Otherwise the field will be blank (although the value will still be set).
1283 * @param {String} value The value to match
1285 setValue : function(v)
1287 if(Roo.isIOS && this.useNativeIOS){
1288 this.setIOSValue(v);
1298 if(this.valueField){
1299 var r = this.findRecord(this.valueField, v);
1301 text = r.data[this.displayField];
1302 }else if(this.valueNotFoundText !== undefined){
1303 text = this.valueNotFoundText;
1306 this.lastSelectionText = text;
1307 if(this.hiddenField){
1308 this.hiddenField.dom.value = v;
1310 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
1313 var close = this.closeTriggerEl();
1316 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
1322 * @property {Object} the last set data for the element
1327 * Sets the value of the field based on a object which is related to the record format for the store.
1328 * @param {Object} value the value to set as. or false on reset?
1330 setFromData : function(o){
1337 var dv = ''; // display value
1338 var vv = ''; // value value..
1340 if (this.displayField) {
1341 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1343 // this is an error condition!!!
1344 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1347 if(this.valueField){
1348 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
1351 var close = this.closeTriggerEl();
1354 (vv.length || vv * 1 > 0) ? close.show() : close.hide();
1357 if(this.hiddenField){
1358 this.hiddenField.dom.value = vv;
1360 this.lastSelectionText = dv;
1361 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1365 // no hidden field.. - we store the value in 'value', but still display
1366 // display field!!!!
1367 this.lastSelectionText = dv;
1368 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
1376 // overridden so that last data is reset..
1383 this.setValue(this.originalValue);
1384 //this.clearInvalid();
1385 this.lastData = false;
1387 this.view.clearSelections();
1393 findRecord : function(prop, value){
1395 if(this.store.getCount() > 0){
1396 this.store.each(function(r){
1397 if(r.data[prop] == value){
1409 // returns hidden if it's set..
1410 if (!this.rendered) {return ''};
1411 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
1415 onViewMove : function(e, t){
1416 this.inKeyMode = false;
1420 onViewOver : function(e, t){
1421 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1424 var item = this.view.findItemFromChild(t);
1427 var index = this.view.indexOf(item);
1428 this.select(index, false);
1433 onViewClick : function(view, doFocus, el, e)
1435 var index = this.view.getSelectedIndexes()[0];
1437 var r = this.store.getAt(index);
1441 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
1448 Roo.each(this.tickItems, function(v,k){
1450 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
1452 _this.tickItems.splice(k, 1);
1454 if(typeof(e) == 'undefined' && view == false){
1455 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
1467 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
1468 this.tickItems.push(r.data);
1471 if(typeof(e) == 'undefined' && view == false){
1472 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
1479 this.onSelect(r, index);
1481 if(doFocus !== false && !this.blockFocus){
1482 this.inputEl().focus();
1487 restrictHeight : function(){
1488 //this.innerList.dom.style.height = '';
1489 //var inner = this.innerList.dom;
1490 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
1491 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
1492 //this.list.beginUpdate();
1493 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
1494 this.list.alignTo(this.inputEl(), this.listAlign);
1495 this.list.alignTo(this.inputEl(), this.listAlign);
1496 //this.list.endUpdate();
1500 onEmptyResults : function(){
1502 if(this.tickable && this.editable){
1503 this.restrictHeight();
1511 * Returns true if the dropdown list is expanded, else false.
1513 isExpanded : function(){
1514 return this.list.isVisible();
1518 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1519 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1520 * @param {String} value The data value of the item to select
1521 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1522 * selected item if it is not currently in view (defaults to true)
1523 * @return {Boolean} True if the value matched an item in the list, else false
1525 selectByValue : function(v, scrollIntoView){
1526 if(v !== undefined && v !== null){
1527 var r = this.findRecord(this.valueField || this.displayField, v);
1529 this.select(this.store.indexOf(r), scrollIntoView);
1537 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1538 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1539 * @param {Number} index The zero-based index of the list item to select
1540 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1541 * selected item if it is not currently in view (defaults to true)
1543 select : function(index, scrollIntoView){
1544 this.selectedIndex = index;
1545 this.view.select(index);
1546 if(scrollIntoView !== false){
1547 var el = this.view.getNode(index);
1549 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
1552 this.list.scrollChildIntoView(el, false);
1558 selectNext : function(){
1559 var ct = this.store.getCount();
1561 if(this.selectedIndex == -1){
1563 }else if(this.selectedIndex < ct-1){
1564 this.select(this.selectedIndex+1);
1570 selectPrev : function(){
1571 var ct = this.store.getCount();
1573 if(this.selectedIndex == -1){
1575 }else if(this.selectedIndex != 0){
1576 this.select(this.selectedIndex-1);
1582 onKeyUp : function(e){
1583 if(this.editable !== false && !e.isSpecialKey()){
1584 this.lastKey = e.getKey();
1585 this.dqTask.delay(this.queryDelay);
1590 validateBlur : function(){
1591 return !this.list || !this.list.isVisible();
1595 initQuery : function(){
1597 var v = this.getRawValue();
1599 if(this.tickable && this.editable){
1600 v = this.tickableInputEl().getValue();
1607 doForce : function(){
1608 if(this.inputEl().dom.value.length > 0){
1609 this.inputEl().dom.value =
1610 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
1616 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
1617 * query allowing the query action to be canceled if needed.
1618 * @param {String} query The SQL query to execute
1619 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
1620 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
1621 * saved in the current store (defaults to false)
1623 doQuery : function(q, forceAll){
1625 if(q === undefined || q === null){
1634 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1639 forceAll = qe.forceAll;
1640 if(forceAll === true || (q.length >= this.minChars)){
1642 this.hasQuery = true;
1644 if(this.lastQuery != q || this.alwaysQuery){
1646 if(this.mode == 'local'){
1647 this.selectedIndex = -1;
1649 this.store.clearFilter();
1652 if(this.specialFilter){
1653 this.fireEvent('specialfilter', this);
1658 this.store.filter(this.displayField, q);
1661 this.store.fireEvent("datachanged", this.store);
1668 this.store.baseParams[this.queryParam] = q;
1670 var options = {params : this.getParams(q)};
1674 options.params.start = this.page * this.pageSize;
1677 this.store.load(options);
1680 * this code will make the page width larger, at the beginning, the list not align correctly,
1681 * we should expand the list on onLoad
1687 this.selectedIndex = -1;
1692 this.loadNext = false;
1696 getParams : function(q){
1698 //p[this.queryParam] = q;
1702 p.limit = this.pageSize;
1708 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
1710 collapse : function(){
1711 if(!this.isExpanded()){
1717 this.hasFocus = false;
1721 this.cancelBtn.hide();
1722 this.trigger.show();
1725 this.tickableInputEl().dom.value = '';
1726 this.tickableInputEl().blur();
1731 Roo.get(document).un('mousedown', this.collapseIf, this);
1732 Roo.get(document).un('mousewheel', this.collapseIf, this);
1733 if (!this.editable) {
1734 Roo.get(document).un('keydown', this.listKeyPress, this);
1736 this.fireEvent('collapse', this);
1742 collapseIf : function(e){
1743 var in_combo = e.within(this.el);
1744 var in_list = e.within(this.list);
1745 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
1747 if (in_combo || in_list || is_list) {
1748 //e.stopPropagation();
1753 this.onTickableFooterButtonClick(e, false, false);
1761 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
1763 expand : function(){
1765 if(this.isExpanded() || !this.hasFocus){
1769 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
1770 this.list.setWidth(lw);
1776 this.restrictHeight();
1780 this.tickItems = Roo.apply([], this.item);
1783 this.cancelBtn.show();
1784 this.trigger.hide();
1787 this.tickableInputEl().focus();
1792 Roo.get(document).on('mousedown', this.collapseIf, this);
1793 Roo.get(document).on('mousewheel', this.collapseIf, this);
1794 if (!this.editable) {
1795 Roo.get(document).on('keydown', this.listKeyPress, this);
1798 this.fireEvent('expand', this);
1802 // Implements the default empty TriggerField.onTriggerClick function
1803 onTriggerClick : function(e)
1805 Roo.log('trigger click');
1807 if(this.disabled || !this.triggerList){
1812 this.loadNext = false;
1814 if(this.isExpanded()){
1816 if (!this.blockFocus) {
1817 this.inputEl().focus();
1821 this.hasFocus = true;
1822 if(this.triggerAction == 'all') {
1823 this.doQuery(this.allQuery, true);
1825 this.doQuery(this.getRawValue());
1827 if (!this.blockFocus) {
1828 this.inputEl().focus();
1833 onTickableTriggerClick : function(e)
1840 this.loadNext = false;
1841 this.hasFocus = true;
1843 if(this.triggerAction == 'all') {
1844 this.doQuery(this.allQuery, true);
1846 this.doQuery(this.getRawValue());
1850 onSearchFieldClick : function(e)
1852 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
1853 this.onTickableFooterButtonClick(e, false, false);
1857 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
1862 this.loadNext = false;
1863 this.hasFocus = true;
1865 if(this.triggerAction == 'all') {
1866 this.doQuery(this.allQuery, true);
1868 this.doQuery(this.getRawValue());
1872 listKeyPress : function(e)
1874 //Roo.log('listkeypress');
1875 // scroll to first matching element based on key pres..
1876 if (e.isSpecialKey()) {
1879 var k = String.fromCharCode(e.getKey()).toUpperCase();
1882 var csel = this.view.getSelectedNodes();
1883 var cselitem = false;
1885 var ix = this.view.indexOf(csel[0]);
1886 cselitem = this.store.getAt(ix);
1887 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
1893 this.store.each(function(v) {
1895 // start at existing selection.
1896 if (cselitem.id == v.id) {
1902 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
1903 match = this.store.indexOf(v);
1909 if (match === false) {
1910 return true; // no more action?
1913 this.view.select(match);
1914 var sn = Roo.get(this.view.getSelectedNodes()[0]);
1915 sn.scrollIntoView(sn.dom.parentNode, false);
1918 onViewScroll : function(e, t){
1920 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){
1924 this.hasQuery = true;
1926 this.loading = this.list.select('.loading', true).first();
1928 if(this.loading === null){
1929 this.list.createChild({
1931 cls: 'loading roo-select2-more-results roo-select2-active',
1932 html: 'Loading more results...'
1935 this.loading = this.list.select('.loading', true).first();
1937 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
1939 this.loading.hide();
1942 this.loading.show();
1947 this.loadNext = true;
1949 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
1954 addItem : function(o)
1956 var dv = ''; // display value
1958 if (this.displayField) {
1959 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
1961 // this is an error condition!!!
1962 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
1969 var choice = this.choices.createChild({
1971 cls: 'roo-select2-search-choice',
1980 cls: 'roo-select2-search-choice-close',
1985 }, this.searchField);
1987 var close = choice.select('a.roo-select2-search-choice-close', true).first();
1989 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
1997 this.inputEl().dom.value = '';
2002 onRemoveItem : function(e, _self, o)
2006 this.lastItem = Roo.apply([], this.item);
2008 var index = this.item.indexOf(o.data) * 1;
2011 Roo.log('not this item?!');
2015 this.item.splice(index, 1);
2020 this.fireEvent('remove', this, e);
2026 syncValue : function()
2028 if(!this.item.length){
2035 Roo.each(this.item, function(i){
2036 if(_this.valueField){
2037 value.push(i[_this.valueField]);
2044 this.value = value.join(',');
2046 if(this.hiddenField){
2047 this.hiddenField.dom.value = this.value;
2050 this.store.fireEvent("datachanged", this.store);
2055 clearItem : function()
2063 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
2071 if(this.tickable && !Roo.isTouch){
2072 this.view.refresh();
2076 inputEl: function ()
2078 if(Roo.isIOS && this.useNativeIOS){
2079 return this.el.select('select.roo-ios-select', true).first();
2082 if(Roo.isTouch && this.mobileTouchView){
2083 return this.el.select('input.form-control',true).first();
2087 return this.searchField;
2090 return this.el.select('input.form-control',true).first();
2093 onTickableFooterButtonClick : function(e, btn, el)
2097 this.lastItem = Roo.apply([], this.item);
2099 if(btn && btn.name == 'cancel'){
2100 this.tickItems = Roo.apply([], this.item);
2109 Roo.each(this.tickItems, function(o){
2117 validate : function()
2119 var v = this.getRawValue();
2122 v = this.getValue();
2125 if(this.disabled || this.allowBlank || v.length){
2134 tickableInputEl : function()
2136 if(!this.tickable || !this.editable){
2137 return this.inputEl();
2140 return this.inputEl().select('.roo-select2-search-field-input', true).first();
2144 getAutoCreateTouchView : function()
2149 cls: 'form-group' //input-group
2155 type : this.inputType,
2156 cls : 'form-control x-combo-noedit',
2157 autocomplete: 'new-password',
2158 placeholder : this.placeholder || '',
2163 input.name = this.name;
2167 input.cls += ' input-' + this.size;
2170 if (this.disabled) {
2171 input.disabled = true;
2182 inputblock.cls += ' input-group';
2184 inputblock.cn.unshift({
2186 cls : 'input-group-addon',
2191 if(this.removable && !this.multiple){
2192 inputblock.cls += ' roo-removable';
2194 inputblock.cn.push({
2197 cls : 'roo-combo-removable-btn close'
2201 if(this.hasFeedback && !this.allowBlank){
2203 inputblock.cls += ' has-feedback';
2205 inputblock.cn.push({
2207 cls: 'glyphicon form-control-feedback'
2214 inputblock.cls += (this.before) ? '' : ' input-group';
2216 inputblock.cn.push({
2218 cls : 'input-group-addon',
2229 cls: 'form-hidden-field'
2243 cls: 'form-hidden-field'
2247 cls: 'roo-select2-choices',
2251 cls: 'roo-select2-search-field',
2264 cls: 'roo-select2-container input-group roo-touchview-combobox ',
2270 if(!this.multiple && this.showToggleBtn){
2277 if (this.caret != false) {
2280 cls: 'fa fa-' + this.caret
2287 cls : 'input-group-addon btn dropdown-toggle',
2292 cls: 'combobox-clear',
2306 combobox.cls += ' roo-select2-container-multi';
2309 var align = this.labelAlign || this.parentLabelAlign();
2313 if(this.fieldLabel.length && this.labelWidth){
2315 var lw = align === 'left' ? ('col-sm' + this.labelWidth) : '';
2316 var cw = align === 'left' ? ('col-sm' + (12 - this.labelWidth)) : '';
2321 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
2322 tooltip : 'This field is required'
2326 cls : 'control-label ' + lw,
2327 html : this.fieldLabel
2338 if(this.indicatorpos == 'right'){
2342 cls : 'control-label ' + lw,
2343 html : this.fieldLabel
2348 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
2349 tooltip : 'This field is required'
2361 var settings = this;
2363 ['xs','sm','md','lg'].map(function(size){
2364 if (settings[size]) {
2365 cfg.cls += ' col-' + size + '-' + settings[size];
2372 initTouchView : function()
2374 this.renderTouchView();
2376 this.touchViewEl.on('scroll', function(){
2377 this.el.dom.scrollTop = 0;
2380 this.originalValue = this.getValue();
2382 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
2384 this.inputEl().on("click", this.showTouchView, this);
2385 if (this.triggerEl) {
2386 this.triggerEl.on("click", this.showTouchView, this);
2390 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
2391 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
2393 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
2395 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
2396 this.store.on('load', this.onTouchViewLoad, this);
2397 this.store.on('loadexception', this.onTouchViewLoadException, this);
2399 if(this.hiddenName){
2401 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
2403 this.hiddenField.dom.value =
2404 this.hiddenValue !== undefined ? this.hiddenValue :
2405 this.value !== undefined ? this.value : '';
2407 this.el.dom.removeAttribute('name');
2408 this.hiddenField.dom.setAttribute('name', this.hiddenName);
2412 this.choices = this.el.select('ul.roo-select2-choices', true).first();
2413 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
2416 if(this.removable && !this.multiple){
2417 var close = this.closeTriggerEl();
2419 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
2420 close.on('click', this.removeBtnClick, this, close);
2424 * fix the bug in Safari iOS8
2426 this.inputEl().on("focus", function(e){
2427 document.activeElement.blur();
2435 renderTouchView : function()
2437 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
2438 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2440 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
2441 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2443 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
2444 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2445 this.touchViewBodyEl.setStyle('overflow', 'auto');
2447 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
2448 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2450 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
2451 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
2455 showTouchView : function()
2461 this.touchViewHeaderEl.hide();
2463 if(this.modalTitle.length){
2464 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
2465 this.touchViewHeaderEl.show();
2468 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2469 this.touchViewEl.show();
2471 this.touchViewEl.select('.modal-dialog', true).first().setStyle('margin', '0px');
2472 this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
2473 Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2475 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2477 if(this.modalTitle.length){
2478 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2481 this.touchViewBodyEl.setHeight(bodyHeight);
2485 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
2487 this.touchViewEl.addClass('in');
2490 this.doTouchViewQuery();
2494 hideTouchView : function()
2496 this.touchViewEl.removeClass('in');
2500 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
2502 this.touchViewEl.setStyle('display', 'none');
2507 setTouchViewValue : function()
2514 Roo.each(this.tickItems, function(o){
2519 this.hideTouchView();
2522 doTouchViewQuery : function()
2531 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
2535 if(!this.alwaysQuery || this.mode == 'local'){
2536 this.onTouchViewLoad();
2543 onTouchViewBeforeLoad : function(combo,opts)
2549 onTouchViewLoad : function()
2551 if(this.store.getCount() < 1){
2552 this.onTouchViewEmptyResults();
2556 this.clearTouchView();
2558 var rawValue = this.getRawValue();
2560 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
2562 this.tickItems = [];
2564 this.store.data.each(function(d, rowIndex){
2565 var row = this.touchViewListGroup.createChild(template);
2567 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
2568 row.addClass(d.data.cls);
2571 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2574 html : d.data[this.displayField]
2577 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
2578 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
2581 row.removeClass('selected');
2582 if(!this.multiple && this.valueField &&
2583 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
2586 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2587 row.addClass('selected');
2590 if(this.multiple && this.valueField &&
2591 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
2595 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2596 this.tickItems.push(d.data);
2599 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
2603 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
2605 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
2607 if(this.modalTitle.length){
2608 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
2611 var listHeight = this.touchViewListGroup.getHeight();
2615 if(firstChecked && listHeight > bodyHeight){
2616 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
2621 onTouchViewLoadException : function()
2623 this.hideTouchView();
2626 onTouchViewEmptyResults : function()
2628 this.clearTouchView();
2630 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
2632 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
2636 clearTouchView : function()
2638 this.touchViewListGroup.dom.innerHTML = '';
2641 onTouchViewClick : function(e, el, o)
2646 var rowIndex = o.rowIndex;
2648 var r = this.store.getAt(rowIndex);
2650 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
2653 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
2654 c.dom.removeAttribute('checked');
2657 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2659 this.setFromData(r.data);
2661 var close = this.closeTriggerEl();
2667 this.hideTouchView();
2669 this.fireEvent('select', this, r, rowIndex);
2674 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
2675 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
2676 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
2680 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
2681 this.addItem(r.data);
2682 this.tickItems.push(r.data);
2686 getAutoCreateNativeIOS : function()
2689 cls: 'form-group' //input-group,
2694 cls : 'roo-ios-select'
2698 combobox.name = this.name;
2701 if (this.disabled) {
2702 combobox.disabled = true;
2705 var settings = this;
2707 ['xs','sm','md','lg'].map(function(size){
2708 if (settings[size]) {
2709 cfg.cls += ' col-' + size + '-' + settings[size];
2719 initIOSView : function()
2721 this.store.on('load', this.onIOSViewLoad, this);
2726 onIOSViewLoad : function()
2728 if(this.store.getCount() < 1){
2732 this.clearIOSView();
2734 if(this.allowBlank) {
2736 var default_text = '-- SELECT --';
2738 var opt = this.inputEl().createChild({
2745 o[this.valueField] = 0;
2746 o[this.displayField] = default_text;
2748 this.ios_options.push({
2755 this.store.data.each(function(d, rowIndex){
2759 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
2760 html = d.data[this.displayField];
2765 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
2766 value = d.data[this.valueField];
2775 if(this.value == d.data[this.valueField]){
2776 option['selected'] = true;
2779 var opt = this.inputEl().createChild(option);
2781 this.ios_options.push({
2788 this.inputEl().on('change', function(){
2789 this.fireEvent('select', this);
2794 clearIOSView: function()
2796 this.inputEl().dom.innerHTML = '';
2798 this.ios_options = [];
2801 setIOSValue: function(v)
2805 if(!this.ios_options){
2809 Roo.each(this.ios_options, function(opts){
2811 opts.el.dom.removeAttribute('selected');
2813 if(opts.data[this.valueField] != v){
2817 opts.el.dom.setAttribute('selected', true);
2823 * @cfg {Boolean} grow
2827 * @cfg {Number} growMin
2831 * @cfg {Number} growMax
2840 Roo.apply(Roo.bootstrap.ComboBox, {
2844 cls: 'modal-header',
2866 cls: 'list-group-item',
2870 cls: 'roo-combobox-list-group-item-value'
2874 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
2888 listItemCheckbox : {
2890 cls: 'list-group-item',
2894 cls: 'roo-combobox-list-group-item-value'
2898 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
2914 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
2919 cls: 'modal-footer',
2927 cls: 'col-xs-6 text-left',
2930 cls: 'btn btn-danger roo-touch-view-cancel',
2936 cls: 'col-xs-6 text-right',
2939 cls: 'btn btn-success roo-touch-view-ok',
2950 Roo.apply(Roo.bootstrap.ComboBox, {
2952 touchViewTemplate : {
2954 cls: 'modal fade roo-combobox-touch-view',
2958 cls: 'modal-dialog',
2959 style : 'position:fixed', // we have to fix position....
2963 cls: 'modal-content',
2965 Roo.bootstrap.ComboBox.header,
2966 Roo.bootstrap.ComboBox.body,
2967 Roo.bootstrap.ComboBox.footer