text: Ext.define("Ext.form.field.ComboBox",{extend:"Ext.form.field.Picker",requires:["Ext.util.DelayedTask","Ext.EventObject","Ext.view.BoundList","Ext.view.BoundListKeyNav","Ext.data.StoreManager","Ext.layout.component.field.ComboBox"],alternateClassName:"Ext.form.ComboBox",alias:["widget.combobox","widget.combo"],mixins:{bindable:"Ext.util.Bindable"},componentLayout:"combobox",triggerCls:Ext.baseCSSPrefix+"form-arrow-trigger",hiddenName:"",hiddenDataCls:Ext.baseCSSPrefix+"hide-display "+Ext.baseCSSPrefix+"form-data-hidden",fieldSubTpl:['<div class="{hiddenDataCls}" role="presentation"></div>','<input id="{id}" type="{type}" {inputAttrTpl} class="{fieldCls} {typeCls} {editableCls}" autocomplete="off"','<tpl if="value"> value="{[Ext.util.Format.htmlEncode(values.value)]}"</tpl>','<tpl if="name"> name="{name}"</tpl>','<tpl if="placeholder"> placeholder="{placeholder}"</tpl>','<tpl if="size"> size="{size}"</tpl>','<tpl if="maxLength !== undefined"> maxlength="{maxLength}"</tpl>','<tpl if="readOnly"> readonly="readonly"</tpl>','<tpl if="disabled"> disabled="disabled"</tpl>','<tpl if="tabIdx"> tabIndex="{tabIdx}"</tpl>','<tpl if="fieldStyle"> style="{fieldStyle}"</tpl>',"/>",{compiled:true,disableFormats:true}],getSubTplData:function(){var a=this;Ext.applyIf(a.subTplData,{hiddenDataCls:a.hiddenDataCls});return a.callParent(arguments)},afterRender:function(){var a=this;a.callParent(arguments);a.setHiddenValue(a.value)},multiSelect:false,delimiter:", ",displayField:"text",triggerAction:"all",allQuery:"",queryParam:"query",queryMode:"remote",queryCaching:true,pageSize:0,anyMatch:false,caseSensitive:false,autoSelect:true,typeAhead:false,typeAheadDelay:250,selectOnTab:true,forceSelection:false,growToLongestValue:true,defaultListConfig:{loadingHeight:70,minWidth:70,maxHeight:300,shadow:"sides"},ignoreSelection:0,removingRecords:null,resizeComboToGrow:function(){var a=this;return a.grow&&a.growToLongestValue},initComponent:function(){var e=this,c=Ext.isDefined,b=e.store,d=e.transform,a,f;Ext.applyIf(e.renderSelectors,{hiddenDataEl:"."+e.hiddenDataCls.split(" ").join(".")});if(e.typeAhead&&e.multiSelect){Ext.Error.raise("typeAhead and multiSelect are mutually exclusive options -- please remove one of them.")}if(e.typeAhead&&!e.editable){Ext.Error.raise("If typeAhead is enabled the combo must be editable: true -- please change one of those settings.")}if(e.selectOnFocus&&!e.editable){Ext.Error.raise("If selectOnFocus is enabled the combo must be editable: true -- please change one of those settings.")}this.addEvents("beforequery","select","beforeselect","beforedeselect");if(d){a=Ext.getDom(d);if(a){if(!e.store){b=Ext.Array.map(Ext.Array.from(a.options),function(g){return[g.value,g.text]})}if(!e.name){e.name=a.name}if(!("value" in e)){e.value=a.value}}}e.bindStore(b||"ext-empty-store",true);b=e.store;if(b.autoCreated){e.queryMode="local";e.valueField=e.displayField="field1";if(!b.expanded){e.displayField="field2"}}if(!c(e.valueField)){e.valueField=e.displayField}f=e.queryMode==="local";if(!c(e.queryDelay)){e.queryDelay=f?10:500}if(!c(e.minChars)){e.minChars=f?0:4}if(!e.displayTpl){e.displayTpl=new Ext.XTemplate('<tpl for=".">{[typeof values === "string" ? values : values["'+e.displayField+'"]]}<tpl if="xindex < xcount">'+e.delimiter+"</tpl></tpl>")}else{if(Ext.isString(e.displayTpl)){e.displayTpl=new Ext.XTemplate(e.displayTpl)}}e.callParent();e.doQueryTask=new Ext.util.DelayedTask(e.doRawQuery,e);if(e.store.getCount()>0){e.setValue(e.value)}if(a){e.render(a.parentNode,a);Ext.removeNode(a);delete e.renderTo}},getStore:function(){return this.store},beforeBlur:function(){this.doQueryTask.cancel();this.assertValue()},assertValue:function(){var b=this,c=b.getRawValue(),d,a;if(b.forceSelection){if(b.multiSelect){if(c!==b.getDisplayValue()){b.setValue(b.lastSelection)}}else{d=b.findRecordByDisplay(c);if(d){a=b.value;if(!b.findRecordByValue(a)){b.select(d,true)}}else{b.setValue(b.lastSelection)}}}b.collapse()},onTypeAhead:function(){var e=this,d=e.displayField,b=e.store.findRecord(d,e.getRawValue()),c=e.getPicker(),f,a,g;if(b){f=b.get(d);a=f.length;g=e.getRawValue().length;c.highlightItem(c.getNode(b));if(g!==0&&g!==a){e.setRawValue(f);e.selectText(g,f.length)}}},resetToDefault:Ext.emptyFn,beforeReset:function(){this.callParent();if(this.queryFilter&&!this.queryFilter.disabled){this.queryFilter.disabled=true;this.store.filter()}},onUnbindStore:function(a){var c=this,b=c.picker;if(c.queryFilter){c.store.removeFilter(c.queryFilter)}if(!a&&b){b.bindStore(null)}},onBindStore:function(a,c){var b=this.picker;if(!c){this.resetToDefault()}if(b){b.bindStore(a)}},getStoreListeners:function(){var a=this;return{beforeload:a.onBeforeLoad,clear:a.onClear,datachanged:a.onDataChanged,load:a.onLoad,exception:a.onException,remove:a.onRemove}},onBeforeLoad:function(){++this.ignoreSelection},onDataChanged:function(){var a=this;if(a.resizeComboToGrow()){a.updateLayout()}},onClear:function(){var a=this;if(a.resizeComboToGrow()){a.removingRecords=true;a.onDataChanged()}},onRemove:function(){var a=this;if(a.resizeComboToGrow()){a.removingRecords=true}},onException:function(){if(this.ignoreSelection>0){--this.ignoreSelection}this.collapse()},onLoad:function(b,a,d){var c=this;if(c.ignoreSelection>0){--c.ignoreSelection}if(d&&!b.lastOptions.rawQuery){if(c.value==null){if(c.store.getCount()){c.doAutoSelect()}else{c.setValue(c.value)}}else{c.setValue(c.value)}}},doRawQuery:function(){this.doQuery(this.getRawValue(),false,true)},doQuery:function(e,b,d){var c=this,a=c.beforeQuery({query:e||"",rawQuery:d,forceAll:b,combo:c,cancel:false});if(a===false||a.cancel){return false}if(c.queryCaching&&a.query===c.lastQuery){c.expand()}else{c.lastQuery=a.query;if(c.queryMode==="local"){c.doLocalQuery(a)}else{c.doRemoteQuery(a)}}return true},beforeQuery:function(a){var b=this;if(b.fireEvent("beforequery",a)===false){a.cancel=true}else{if(!a.cancel){if(a.query.length<b.minChars&&!a.forceAll){a.cancel=true}}}return a},doLocalQuery:function(a){var b=this,c=a.query;if(!b.queryFilter){b.queryFilter=new Ext.util.Filter({id:b.id+"-query-filter",anyMatch:b.anyMatch,caseSensitive:b.caseSensitive,root:"data",property:b.displayField});b.store.addFilter(b.queryFilter,false)}if(c||!a.forceAll){b.queryFilter.disabled=false;b.queryFilter.setValue(b.enableRegEx?new RegExp(c):c)}else{b.queryFilter.disabled=true}b.store.filter();if(b.store.getCount()){b.expand()}else{b.collapse()}b.afterQuery(a)},doRemoteQuery:function(b){var c=this,a=function(){c.afterQuery(b)};c.expand();if(c.pageSize){c.loadPage(1,{rawQuery:b.rawQuery,callback:a})}else{c.store.load({params:c.getParams(b.query),rawQuery:b.rawQuery,callback:a})}},afterQuery:function(a){var b=this;if(b.store.getCount()){if(b.typeAhead){b.doTypeAhead()}if(b.getRawValue()!==b.getDisplayValue()){b.ignoreSelection++;b.picker.getSelectionModel().deselectAll();b.ignoreSelection--}if(a.rawQuery){b.syncSelection();if(b.picker&&!b.picker.getSelectionModel().hasSelection()){b.doAutoSelect()}}else{b.doAutoSelect()}}},loadPage:function(b,a){this.store.loadPage(b,Ext.apply({params:this.getParams(this.lastQuery)},a))},onPageChange:function(b,a){this.loadPage(a);return false},getParams:function(c){var b={},a=this.queryParam;if(a){b[a]=c}return b},doAutoSelect:function(){var b=this,a=b.picker,c,d;if(a&&b.autoSelect&&b.store.getCount()>0){c=a.getSelectionModel().lastSelected;d=a.getNode(c||0);if(d){a.highlightItem(d);a.listEl.scrollChildIntoView(d,false)}}},doTypeAhead:function(){if(!this.typeAheadTask){this.typeAheadTask=new Ext.util.DelayedTask(this.onTypeAhead,this)}if(this.lastKey!=Ext.EventObject.BACKSPACE&&this.lastKey!=Ext.EventObject.DELETE){this.typeAheadTask.delay(this.typeAheadDelay)}},onTriggerClick:function(){var a=this;if(!a.readOnly&&!a.disabled){if(a.isExpanded){a.collapse()}else{a.onFocus({});if(a.triggerAction==="all"){a.doQuery(a.allQuery,true)}else{if(a.triggerAction==="last"){a.doQuery(a.lastQuery,true)}else{a.doQuery(a.getRawValue(),false,true)}}}a.inputEl.focus()}},onPaste:function(){var a=this;if(!a.readOnly&&!a.disabled&&a.editable){a.doQueryTask.delay(a.queryDelay)}},onKeyUp:function(d,b){var c=this,a=d.getKey();if(!c.readOnly&&!c.disabled&&c.editable){c.lastKey=a;if(!d.isSpecialKey()||a==d.BACKSPACE||a==d.DELETE){c.doQueryTask.delay(c.queryDelay)}}if(c.enableKeyEvents){c.callParent(arguments)}},initEvents:function(){var a=this;a.callParent();if(!a.enableKeyEvents){a.mon(a.inputEl,"keyup",a.onKeyUp,a)}a.mon(a.inputEl,"paste",a.onPaste,a)},onDestroy:function(){Ext.destroy(this.listKeyNav);this.bindStore(null);this.callParent()},onAdded:function(){var a=this;a.callParent(arguments);if(a.picker){a.picker.ownerCt=a.up("[floating]");a.picker.registerWithOwnerCt()}},createPicker:function(){var c=this,b,a=Ext.apply({xtype:"boundlist",pickerField:c,selModel:{mode:c.multiSelect?"SIMPLE":"SINGLE"},floating:true,hidden:true,store:c.store,displayField:c.displayField,focusOnToFront:false,pageSize:c.pageSize,tpl:c.tpl},c.listConfig,c.defaultListConfig);b=c.picker=Ext.widget(a);if(c.pageSize){b.pagingToolbar.on("beforechange",c.onPageChange,c)}c.mon(b,{itemclick:c.onItemClick,refresh:c.onListRefresh,scope:c});c.mon(b.getSelectionModel(),{beforeselect:c.onBeforeSelect,beforedeselect:c.onBeforeDeselect,selectionchange:c.onListSelectionChange,scope:c});return b},alignPicker:function(){var b=this,a=b.getPicker(),e=b.getPosition()[1]-Ext.getBody().getScroll().top,d=Ext.Element.getViewHeight()-e-b.getHeight(),c=Math.max(e,d);if(a.height){delete a.height;a.updateLayout()}if(a.getHeight()>c-5){a.setHeight(c-5)}b.callParent()},onListRefresh:function(){if(!this.expanding){this.alignPicker()}this.syncSelection()},onItemClick:function(c,a){var e=this,d=e.picker.getSelectionModel().getSelection(),b=e.valueField;if(!e.multiSelect&&d.length){if(a.get(b)===d[0].get(b)){e.displayTplData=[a.data];e.setRawValue(e.getDisplayValue());e.collapse()}}},onBeforeSelect:function(b,a){return this.fireEvent("beforeselect",this,a,a.index)},onBeforeDeselect:function(b,a){return this.fireEvent("beforedeselect",this,a,a.index)},onListSelectionChange:function(b,d){var a=this,e=a.multiSelect,c=d.length>0;if(!a.ignoreSelection&&a.isExpanded){if(!e){Ext.defer(a.collapse,1,a)}if(e||c){a.setValue(d,false)}if(c){a.fireEvent("select",a,d)}a.inputEl.focus()}},onExpand:function(){var d=this,a=d.listKeyNav,c=d.selectOnTab,b=d.getPicker();if(a){a.enable()}else{a=d.listKeyNav=new Ext.view.BoundListKeyNav(this.inputEl,{boundList:b,forceKeyDown:true,tab:function(f){if(c){this.selectHighlighted(f);d.triggerBlur()}return true},enter:function(h){var f=b.getSelectionModel(),g=f.getCount();this.selectHighlighted(h);if(!d.multiSelect&&g===f.getCount()){d.collapse()}}})}if(c){d.ignoreMonitorTab=true}Ext.defer(a.enable,1,a);d.inputEl.focus()},onCollapse:function(){var b=this,a=b.listKeyNav;if(a){a.disable();b.ignoreMonitorTab=false}},select:function(e,b){var d=this,c=d.picker,a=true,f;if(e&&e.isModel&&b===true&&c){f=!c.getSelectionModel().isSelected(e)}d.setValue(e,true);if(f){d.fireEvent("select",d,e)}},findRecord:function(d,c){var b=this.store,a=b.findExact(d,c);return a!==-1?b.getAt(a):false},findRecordByValue:function(a){return this.findRecord(this.valueField,a)},findRecordByDisplay:function(a){return this.findRecord(this.displayField,a)},setValue:function(l,e){var j=this,c=j.valueNotFoundText,m=j.inputEl,f,h,g,a,k=[],b=[],d=[];if(j.store.loading){j.value=l;j.setHiddenValue(j.value);return j}l=Ext.Array.from(l);for(f=0,h=l.length;f<h;f++){g=l[f];if(!g||!g.isModel){g=j.findRecordByValue(g)}if(g){k.push(g);b.push(g.data);d.push(g.get(j.valueField))}else{if(!j.forceSelection){d.push(l[f]);a={};a[j.displayField]=l[f];b.push(a)}else{if(Ext.isDefined(c)){b.push(c)}}}}j.setHiddenValue(d);j.value=j.multiSelect?d:d[0];if(!Ext.isDefined(j.value)){j.value=null}j.displayTplData=b;j.lastSelection=j.valueModels=k;if(m&&j.emptyText&&!Ext.isEmpty(l)){m.removeCls(j.emptyCls)}j.setRawValue(j.getDisplayValue());j.checkChange();if(e!==false){j.syncSelection()}j.applyEmptyText();return j},setHiddenValue:function(h){var e=this,a=e.hiddenName,d,b,j,g,f,c;if(!e.hiddenDataEl||!a){return}h=Ext.Array.from(h);b=e.hiddenDataEl.dom;j=b.childNodes;g=j[0];f=h.length;c=j.length;if(!g&&f>0){e.hiddenDataEl.update(Ext.DomHelper.markup({tag:"input",type:"hidden",name:a}));c=1;g=b.firstChild}while(c>f){b.removeChild(j[0]);--c}while(c<f){b.appendChild(g.cloneNode(true));++c}for(d=0;d<f;d++){j[d].value=h[d]}},getDisplayValue:function(){return this.displayTpl.apply(this.displayTplData)},getValue:function(){var b=this,a=b.picker,d=b.getRawValue(),c=b.value;if(b.getDisplayValue()!==d){c=d;b.value=b.displayTplData=b.valueModels=null;if(a){b.ignoreSelection++;a.getSelectionModel().deselectAll();b.ignoreSelection--}}return c},getSubmitValue:function(){var a=this.getValue();if(Ext.isEmpty(a)){a=""}return a},isEqual:function(e,d){var b=Ext.Array.from,c,a;e=b(e);d=b(d);a=e.length;if(a!==d.length){return false}for(c=0;c<a;c++){if(d[c]!==e[c]){return false}}return true},clearValue:function(){this.setValue([])},syncSelection:function(){var g=this,d=g.picker,f,c,b=g.valueModels||[],e=b.length,a,h;if(d){f=[];for(a=0;a<e;a++){h=b[a];if(h&&h.isModel&&g.store.indexOf(h)>=0){f.push(h)}}g.ignoreSelection++;c=d.getSelectionModel();c.deselectAll();if(f.length){c.select(f,undefined,true)}g.ignoreSelection--}},onEditorTab:function(b){var a=this.listKeyNav;if(this.selectOnTab&&a){a.selectHighlighted(b)}}});