3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.form.ComboBox"></div>/**
16 * @class Ext.form.ComboBox
17 * @extends Ext.form.TriggerField
18 * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
19 * <p>A ComboBox works in a similar manner to a traditional HTML <select> field. The difference is
20 * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
21 * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
22 * which is named according to the {@link #name}.</p>
23 * <p><b><u>Events</u></b></p>
24 * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
25 var cb = new Ext.form.ComboBox({
26 // all of your config options
29 'select': yourFunction
33 // Alternatively, you can assign events after the object is created:
34 var cb = new Ext.form.ComboBox(yourOptions);
35 cb.on('select', yourFunction, yourScope);
38 * <p><b><u>ComboBox in Grid</u></b></p>
39 * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
40 * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
41 * a reusable render, for example:<pre><code>
42 // create reusable renderer
43 Ext.util.Format.comboRenderer = function(combo){
44 return function(value){
45 var record = combo.findRecord(combo.{@link #valueField}, value);
46 return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
50 // create the combo instance
51 var combo = new Ext.form.ComboBox({
52 {@link #typeAhead}: true,
53 {@link #triggerAction}: 'all',
54 {@link #lazyRender}:true,
55 {@link #mode}: 'local',
56 {@link #store}: new Ext.data.ArrayStore({
62 data: [[1, 'item1'], [2, 'item2']]
64 {@link #valueField}: 'myId',
65 {@link #displayField}: 'displayText'
68 // snippet of column model used within grid
69 var cm = new Ext.grid.ColumnModel([{
72 header: "Some Header",
73 dataIndex: 'whatever',
75 editor: combo, // specify reference to combo instance
76 renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
82 * <p><b><u>Filtering</u></b></p>
83 * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
84 * store manually see <tt>{@link #lastQuery}</tt>.</p>
86 * Create a new ComboBox.
87 * @param {Object} config Configuration options
90 Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
91 <div id="cfg-Ext.form.ComboBox-transform"></div>/**
92 * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
93 * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
94 * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
96 <div id="cfg-Ext.form.ComboBox-lazyRender"></div>/**
97 * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
98 * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
99 * defaults to <tt>false</tt>).
101 <div id="cfg-Ext.form.ComboBox-autoCreate"></div>/**
102 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
103 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
104 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
105 * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
107 <div id="cfg-Ext.form.ComboBox-store"></div>/**
108 * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
109 * Acceptable values for this property are:
110 * <div class="mdetail-params"><ul>
111 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
112 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally,
113 * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
114 * <div class="mdetail-params"><ul>
115 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
116 * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
117 * {@link #valueField} and {@link #displayField})</div></li>
118 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
119 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
120 * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
121 * </div></li></ul></div></li></ul></div>
122 * <p>See also <tt>{@link #mode}</tt>.</p>
124 <div id="cfg-Ext.form.ComboBox-title"></div>/**
125 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
126 * the dropdown list (defaults to undefined, with no header element)
130 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
131 <div id="cfg-Ext.form.ComboBox-listWidth"></div>/**
132 * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
133 * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}
135 <div id="cfg-Ext.form.ComboBox-displayField"></div>/**
136 * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
137 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field1'</tt> if
138 * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
139 * the store configuration}).
140 * <p>See also <tt>{@link #valueField}</tt>.</p>
141 * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
142 * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
145 <div id="cfg-Ext.form.ComboBox-valueField"></div>/**
146 * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
147 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field2'</tt> if
148 * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
149 * the store configuration}).
150 * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
151 * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
153 <div id="cfg-Ext.form.ComboBox-hiddenName"></div>/**
154 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
155 * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
156 * post during a form submission. See also {@link #valueField}.
157 * <p><b>Note</b>: the hidden field's id will also default to this name if {@link #hiddenId} is not specified.
158 * The ComboBox {@link Ext.Component#id id} and the <tt>{@link #hiddenId}</tt> <b>should be different</b>, since
159 * no two DOM nodes should share the same id. So, if the ComboBox <tt>{@link Ext.form.Field#name name}</tt> and
160 * <tt>hiddenName</tt> are the same, you should specify a unique <tt>{@link #hiddenId}</tt>.</p>
162 <div id="cfg-Ext.form.ComboBox-hiddenId"></div>/**
163 * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
164 * to give the hidden field a unique id (defaults to the <tt>{@link #hiddenName}</tt>). The <tt>hiddenId</tt>
165 * and combo {@link Ext.Component#id id} should be different, since no two DOM
166 * nodes should share the same id.
168 <div id="cfg-Ext.form.ComboBox-hiddenValue"></div>/**
169 * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
170 * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
171 * <tt>{@link Ext.form.Field#value value}</tt>.
173 <div id="cfg-Ext.form.ComboBox-listClass"></div>/**
174 * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
175 * applied the dropdown list element (defaults to '').
178 <div id="cfg-Ext.form.ComboBox-selectedClass"></div>/**
179 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
180 * (defaults to <tt>'x-combo-selected'</tt>)
182 selectedClass : 'x-combo-selected',
183 <div id="cfg-Ext.form.ComboBox-listEmptyText"></div>/**
184 * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
188 <div id="cfg-Ext.form.ComboBox-triggerClass"></div>/**
189 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
190 * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
191 * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
193 triggerClass : 'x-form-arrow-trigger',
194 <div id="cfg-Ext.form.ComboBox-shadow"></div>/**
195 * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
196 * 4-way shadow, and <tt>"drop"</tt> for bottom-right
199 <div id="cfg-Ext.form.ComboBox-listAlign"></div>/**
200 * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
201 * on supported anchor positions and offsets. To specify x/y offsets as well, this value
202 * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
203 * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
205 listAlign : 'tl-bl?',
206 <div id="cfg-Ext.form.ComboBox-maxHeight"></div>/**
207 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
208 * (defaults to <tt>300</tt>)
211 <div id="cfg-Ext.form.ComboBox-minHeight"></div>/**
212 * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
213 * distance to the viewport edges (defaults to <tt>90</tt>)
216 <div id="cfg-Ext.form.ComboBox-triggerAction"></div>/**
217 * @cfg {String} triggerAction The action to execute when the trigger is clicked.
218 * <div class="mdetail-params"><ul>
219 * <li><b><tt>'query'</tt></b> : <b>Default</b>
220 * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
221 * <li><b><tt>'all'</tt></b> :
222 * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
224 * <p>See also <code>{@link #queryParam}</code>.</p>
226 triggerAction : 'query',
227 <div id="cfg-Ext.form.ComboBox-minChars"></div>/**
228 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
229 * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
230 * <tt>{@link #mode} = 'local'</tt>, does not apply if
231 * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
234 <div id="cfg-Ext.form.ComboBox-autoSelect"></div>/**
235 * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
236 * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
237 * unless the value of ({@link #typeAheadDelay}) were true.
240 <div id="cfg-Ext.form.ComboBox-typeAhead"></div>/**
241 * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
242 * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
246 <div id="cfg-Ext.form.ComboBox-queryDelay"></div>/**
247 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
248 * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
249 * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
252 <div id="cfg-Ext.form.ComboBox-pageSize"></div>/**
253 * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
254 * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
255 * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
256 * (defaults to <tt>0</tt>).
259 <div id="cfg-Ext.form.ComboBox-selectOnFocus"></div>/**
260 * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
261 * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
264 selectOnFocus : false,
265 <div id="cfg-Ext.form.ComboBox-queryParam"></div>/**
266 * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
267 * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
269 queryParam : 'query',
270 <div id="cfg-Ext.form.ComboBox-loadingText"></div>/**
271 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
272 * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
274 loadingText : 'Loading...',
275 <div id="cfg-Ext.form.ComboBox-resizable"></div>/**
276 * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
277 * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
278 * Defaults to <tt>false</tt>.
281 <div id="cfg-Ext.form.ComboBox-handleHeight"></div>/**
282 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
283 * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
286 <div id="cfg-Ext.form.ComboBox-allQuery"></div>/**
287 * @cfg {String} allQuery The text query to send to the server to return all records for the list
288 * with no filtering (defaults to '')
291 <div id="cfg-Ext.form.ComboBox-mode"></div>/**
292 * @cfg {String} mode Acceptable values are:
293 * <div class="mdetail-params"><ul>
294 * <li><b><tt>'remote'</tt></b> : <b>Default</b>
295 * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
296 * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
297 * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
298 * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
299 * <li><b><tt>'local'</tt></b> :
300 * <p class="sub-desc">ComboBox loads local data</p>
302 var combo = new Ext.form.ComboBox({
303 renderTo: document.body,
305 store: new Ext.data.ArrayStore({
308 'myId', // numeric value is the key
311 data: [[1, 'item1'], [2, 'item2']] // data is local
314 displayField: 'displayText',
321 <div id="cfg-Ext.form.ComboBox-minListWidth"></div>/**
322 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
323 * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
326 <div id="cfg-Ext.form.ComboBox-forceSelection"></div>/**
327 * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
328 * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
330 forceSelection : false,
331 <div id="cfg-Ext.form.ComboBox-typeAheadDelay"></div>/**
332 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
333 * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
335 typeAheadDelay : 250,
336 <div id="cfg-Ext.form.ComboBox-valueNotFoundText"></div>/**
337 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
338 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
339 * default text is used, it means there is no value set and no validation will occur on this field.
342 <div id="cfg-Ext.form.ComboBox-lazyInit"></div>/**
343 * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
344 * (defaults to <tt>true</tt>)
348 <div id="cfg-Ext.form.ComboBox-clearFilterOnReset"></div>/**
349 * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
350 * (defaults to <tt>true</tt>)
352 clearFilterOnReset : true,
354 <div id="cfg-Ext.form.ComboBox-submitValue"></div>/**
355 * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
356 * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
357 * Defaults to <tt>undefined</tt>.
359 submitValue: undefined,
361 <div id="prop-Ext.form.ComboBox-lastQuery"></div>/**
362 * The value of the match string used to filter the store. Delete this property to force a requery.
365 var combo = new Ext.form.ComboBox({
370 // delete the previous query in the beforequery event or set
371 // combo.lastQuery = null (this will reload the store the next time it expands)
372 beforequery: function(qe){
373 delete qe.combo.lastQuery;
378 * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
379 * configure the combo with <tt>lastQuery=''</tt>. Example use:
381 var combo = new Ext.form.ComboBox({
384 triggerAction: 'all',
388 * @property lastQuery
393 initComponent : function(){
394 Ext.form.ComboBox.superclass.initComponent.call(this);
396 <div id="event-Ext.form.ComboBox-expand"></div>/**
398 * Fires when the dropdown list is expanded
399 * @param {Ext.form.ComboBox} combo This combo box
402 <div id="event-Ext.form.ComboBox-collapse"></div>/**
404 * Fires when the dropdown list is collapsed
405 * @param {Ext.form.ComboBox} combo This combo box
409 <div id="event-Ext.form.ComboBox-beforeselect"></div>/**
410 * @event beforeselect
411 * Fires before a list item is selected. Return false to cancel the selection.
412 * @param {Ext.form.ComboBox} combo This combo box
413 * @param {Ext.data.Record} record The data record returned from the underlying store
414 * @param {Number} index The index of the selected item in the dropdown list
417 <div id="event-Ext.form.ComboBox-select"></div>/**
419 * Fires when a list item is selected
420 * @param {Ext.form.ComboBox} combo This combo box
421 * @param {Ext.data.Record} record The data record returned from the underlying store
422 * @param {Number} index The index of the selected item in the dropdown list
425 <div id="event-Ext.form.ComboBox-beforequery"></div>/**
427 * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
428 * cancel property to true.
429 * @param {Object} queryEvent An object that has these properties:<ul>
430 * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
431 * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
432 * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
433 * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
439 var s = Ext.getDom(this.transform);
440 if(!this.hiddenName){
441 this.hiddenName = s.name;
445 var d = [], opts = s.options;
446 for(var i = 0, len = opts.length;i < len; i++){
448 value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
449 if(o.selected && Ext.isEmpty(this.value, true)) {
452 d.push([value, o.text]);
454 this.store = new Ext.data.ArrayStore({
456 fields: ['value', 'text'],
460 this.valueField = 'value';
461 this.displayField = 'text';
463 s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
464 if(!this.lazyRender){
466 this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
467 this.render(this.el.parentNode, s);
471 //auto-configure store from local array data
473 this.store = Ext.StoreMgr.lookup(this.store);
474 if(this.store.autoCreated){
475 this.displayField = this.valueField = 'field1';
476 if(!this.store.expandData){
477 this.displayField = 'field2';
483 this.selectedIndex = -1;
484 if(this.mode == 'local'){
485 if(!Ext.isDefined(this.initialConfig.queryDelay)){
486 this.queryDelay = 10;
488 if(!Ext.isDefined(this.initialConfig.minChars)){
495 onRender : function(ct, position){
496 if(this.hiddenName && !Ext.isDefined(this.submitValue)){
497 this.submitValue = false;
499 Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
501 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
502 id: (this.hiddenId||this.hiddenName)}, 'before', true);
506 this.el.dom.setAttribute('autocomplete', 'off');
512 this.on('focus', this.initList, this, {single: true});
517 initValue : function(){
518 Ext.form.ComboBox.superclass.initValue.call(this);
519 if(this.hiddenField){
520 this.hiddenField.value =
521 Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
525 getParentZIndex : function(){
528 this.findParentBy(function(ct){
529 zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
537 initList : function(){
539 var cls = 'x-combo-list',
540 listParent = Ext.getDom(this.getListParent() || Ext.getBody()),
541 zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10);
544 zindex = this.getParentZIndex();
547 this.list = new Ext.Layer({
548 parentEl: listParent,
550 cls: [cls, this.listClass].join(' '),
552 zindex: (zindex || 12000) + 5
555 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
556 this.list.setSize(lw, 0);
557 this.list.swallowEvent('mousewheel');
558 this.assetHeight = 0;
559 if(this.syncFont !== false){
560 this.list.setStyle('font-size', this.el.getStyle('font-size'));
563 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
564 this.assetHeight += this.header.getHeight();
567 this.innerList = this.list.createChild({cls:cls+'-inner'});
568 this.mon(this.innerList, 'mouseover', this.onViewOver, this);
569 this.mon(this.innerList, 'mousemove', this.onViewMove, this);
570 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
573 this.footer = this.list.createChild({cls:cls+'-ft'});
574 this.pageTb = new Ext.PagingToolbar({
576 pageSize: this.pageSize,
579 this.assetHeight += this.footer.getHeight();
583 <div id="cfg-Ext.form.ComboBox-tpl"></div>/**
584 * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
585 * use to display each item in the dropdown list. The dropdown list is displayed in a
586 * DataView. See {@link #view}.</p>
587 * <p>The default template string is:</p><pre><code>
588 '<tpl for="."><div class="x-combo-list-item">{' + this.displayField + '}</div></tpl>'
590 * <p>Override the default value to create custom UI layouts for items in the list.
591 * For example:</p><pre><code>
592 '<tpl for="."><div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>'
594 * <p>The template <b>must</b> contain one or more substitution parameters using field
595 * names from the Combo's</b> {@link #store Store}. In the example above an
596 * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
597 * <p>To preserve the default visual look of list items, add the CSS class name
598 * <pre>x-combo-list-item</pre> to the template's container element.</p>
599 * <p>Also see {@link #itemSelector} for additional details.</p>
601 this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
602 <div id="cfg-Ext.form.ComboBox-itemSelector"></div>/**
603 * @cfg {String} itemSelector
604 * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
605 * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
606 * display will be working with.</p>
607 * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
608 * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
609 * to dropdown list items</b>
613 <div id="prop-Ext.form.ComboBox-view"></div>/**
614 * The {@link Ext.DataView DataView} used to display the ComboBox's options.
617 this.view = new Ext.DataView({
618 applyTo: this.innerList,
621 selectedClass: this.selectedClass,
622 itemSelector: this.itemSelector || '.' + cls + '-item',
623 emptyText: this.listEmptyText,
624 deferEmptyText: false
627 this.mon(this.view, {
628 containerclick : this.onViewClick,
629 click : this.onViewClick,
633 this.bindStore(this.store, true);
636 this.resizer = new Ext.Resizable(this.list, {
637 pinned:true, handles:'se'
639 this.mon(this.resizer, 'resize', function(r, w, h){
640 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
642 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
643 this.restrictHeight();
646 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
651 <div id="method-Ext.form.ComboBox-getListParent"></div>/**
652 * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
653 * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
654 * to a different Element. An example might be rendering the list inside a Menu so that clicking
655 * the list does not hide the Menu:<pre><code>
656 var store = new Ext.data.ArrayStore({
658 fields: ['initials', 'fullname'],
660 ['FF', 'Fred Flintstone'],
661 ['BR', 'Barney Rubble']
665 var combo = new Ext.form.ComboBox({
667 displayField: 'fullname',
668 emptyText: 'Select a name...',
669 forceSelection: true,
670 getListParent: function() {
671 return this.el.up('.x-menu');
673 iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
676 triggerAction: 'all',
681 var menu = new Ext.menu.Menu({
684 combo // A Field in a Menu
689 getListParent : function() {
690 return document.body;
693 <div id="method-Ext.form.ComboBox-getStore"></div>/**
694 * Returns the store associated with this combo.
695 * @return {Ext.data.Store} The store
697 getStore : function(){
702 bindStore : function(store, initial){
703 if(this.store && !initial){
704 if(this.store !== store && this.store.autoDestroy){
705 this.store.destroy();
707 this.store.un('beforeload', this.onBeforeLoad, this);
708 this.store.un('load', this.onLoad, this);
709 this.store.un('exception', this.collapse, this);
714 this.view.bindStore(null);
717 this.pageTb.bindStore(null);
723 this.lastQuery = null;
725 this.pageTb.bindStore(store);
729 this.store = Ext.StoreMgr.lookup(store);
732 beforeload: this.onBeforeLoad,
734 exception: this.collapse
738 this.view.bindStore(store);
744 Ext.form.ComboBox.superclass.reset.call(this);
745 if(this.clearFilterOnReset && this.mode == 'local'){
746 this.store.clearFilter();
751 initEvents : function(){
752 Ext.form.ComboBox.superclass.initEvents.call(this);
754 <div id="prop-Ext.form.ComboBox-keyNav"></div>/**
757 * <p>A {@link Ext.KeyNav KeyNav} object which handles navigation keys for this ComboBox. This performs actions
758 * based on keystrokes typed when the input field is focused.</p>
759 * <p><b>After the ComboBox has been rendered</b>, you may override existing navigation key functionality,
760 * or add your own based upon key names as specified in the {@link Ext.KeyNav KeyNav} class.</p>
761 * <p>The function is executed in the scope (<code>this</code> reference of the ComboBox. Example:</p><pre><code>
762 myCombo.keyNav.esc = function(e) { // Override ESC handling function
763 this.collapse(); // Standard behaviour of Ext's ComboBox.
764 this.setValue(this.startValue); // We reset to starting value on ESC
766 myCombo.keyNav.tab = function() { // Override TAB handling function
767 this.onViewClick(false); // Select the currently highlighted row
771 this.keyNav = new Ext.KeyNav(this.el, {
773 this.inKeyMode = true;
777 "down" : function(e){
778 if(!this.isExpanded()){
779 this.onTriggerClick();
781 this.inKeyMode = true;
786 "enter" : function(e){
795 if (this.forceSelection === true) {
798 this.onViewClick(false);
805 doRelay : function(e, h, hname){
806 if(hname == 'down' || this.scope.isExpanded()){
807 // this MUST be called before ComboBox#fireKey()
808 var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
809 if(!Ext.isIE && Ext.EventManager.useKeydown){
810 // call Combo#fireKey() for browsers which use keydown event (except IE)
811 this.scope.fireKey(e);
819 defaultEventAction: 'stopEvent'
821 this.queryDelay = Math.max(this.queryDelay || 10,
822 this.mode == 'local' ? 10 : 250);
823 this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
825 this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
827 if(!this.enableKeyEvents){
828 this.mon(this.el, 'keyup', this.onKeyUp, this);
834 onDestroy : function(){
836 this.dqTask.cancel();
839 this.bindStore(null);
846 Ext.destroyMembers(this, 'hiddenField');
847 Ext.form.ComboBox.superclass.onDestroy.call(this);
851 fireKey : function(e){
852 if (!this.isExpanded()) {
853 Ext.form.ComboBox.superclass.fireKey.call(this, e);
858 onResize : function(w, h){
859 Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
860 if(!isNaN(w) && this.isVisible() && this.list){
867 doResize: function(w){
868 if(!Ext.isDefined(this.listWidth)){
869 var lw = Math.max(w, this.minListWidth);
870 this.list.setWidth(lw);
871 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
876 onEnable : function(){
877 Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
878 if(this.hiddenField){
879 this.hiddenField.disabled = false;
884 onDisable : function(){
885 Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
886 if(this.hiddenField){
887 this.hiddenField.disabled = true;
892 onBeforeLoad : function(){
896 this.innerList.update(this.loadingText ?
897 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
898 this.restrictHeight();
899 this.selectedIndex = -1;
907 if(this.store.getCount() > 0 || this.listEmptyText){
909 this.restrictHeight();
910 if(this.lastQuery == this.allQuery){
912 this.el.dom.select();
915 if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
916 this.select(0, true);
919 if(this.autoSelect !== false){
922 if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
923 this.taTask.delay(this.typeAheadDelay);
933 onTypeAhead : function(){
934 if(this.store.getCount() > 0){
935 var r = this.store.getAt(0);
936 var newValue = r.data[this.displayField];
937 var len = newValue.length;
938 var selStart = this.getRawValue().length;
940 this.setRawValue(newValue);
941 this.selectText(selStart, newValue.length);
947 assertValue : function(){
948 var val = this.getRawValue(),
949 rec = this.findRecord(this.displayField, val);
951 if(!rec && this.forceSelection){
952 if(val.length > 0 && val != this.emptyText){
953 this.el.dom.value = Ext.value(this.lastSelectionText, '');
954 this.applyEmptyText();
960 // onSelect may have already set the value and by doing so
961 // set the display field properly. Let's not wipe out the
962 // valueField here by just sending the displayField.
963 if (val == rec.get(this.displayField) && this.value == rec.get(this.valueField)){
966 val = rec.get(this.valueField || this.displayField);
973 onSelect : function(record, index){
974 if(this.fireEvent('beforeselect', this, record, index) !== false){
975 this.setValue(record.data[this.valueField || this.displayField]);
977 this.fireEvent('select', this, record, index);
983 var hf = this.hiddenField;
984 return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
987 <div id="method-Ext.form.ComboBox-getValue"></div>/**
988 * Returns the currently selected field value or empty string if no value is set.
989 * @return {String} value The selected value
991 getValue : function(){
993 return Ext.isDefined(this.value) ? this.value : '';
995 return Ext.form.ComboBox.superclass.getValue.call(this);
999 <div id="method-Ext.form.ComboBox-clearValue"></div>/**
1000 * Clears any text/value currently set in the field
1002 clearValue : function(){
1003 if(this.hiddenField){
1004 this.hiddenField.value = '';
1006 this.setRawValue('');
1007 this.lastSelectionText = '';
1008 this.applyEmptyText();
1012 <div id="method-Ext.form.ComboBox-setValue"></div>/**
1013 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1014 * will be displayed in the field. If the value does not match the data value of an existing item,
1015 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1016 * Otherwise the field will be blank (although the value will still be set).
1017 * @param {String} value The value to match
1018 * @return {Ext.form.Field} this
1020 setValue : function(v){
1022 if(this.valueField){
1023 var r = this.findRecord(this.valueField, v);
1025 text = r.data[this.displayField];
1026 }else if(Ext.isDefined(this.valueNotFoundText)){
1027 text = this.valueNotFoundText;
1030 this.lastSelectionText = text;
1031 if(this.hiddenField){
1032 this.hiddenField.value = Ext.value(v, '');
1034 Ext.form.ComboBox.superclass.setValue.call(this, text);
1040 findRecord : function(prop, value){
1042 if(this.store.getCount() > 0){
1043 this.store.each(function(r){
1044 if(r.data[prop] == value){
1054 onViewMove : function(e, t){
1055 this.inKeyMode = false;
1059 onViewOver : function(e, t){
1060 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1063 var item = this.view.findItemFromChild(t);
1065 var index = this.view.indexOf(item);
1066 this.select(index, false);
1071 onViewClick : function(doFocus){
1072 var index = this.view.getSelectedIndexes()[0],
1076 this.onSelect(r, index);
1080 if(doFocus !== false){
1087 restrictHeight : function(){
1088 this.innerList.dom.style.height = '';
1089 var inner = this.innerList.dom,
1090 pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
1091 h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
1092 ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
1093 hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
1094 space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
1096 h = Math.min(h, space, this.maxHeight);
1098 this.innerList.setHeight(h);
1099 this.list.beginUpdate();
1100 this.list.setHeight(h+pad);
1101 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1102 this.list.endUpdate();
1105 <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
1106 * Returns true if the dropdown list is expanded, else false.
1108 isExpanded : function(){
1109 return this.list && this.list.isVisible();
1112 <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
1113 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1114 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1115 * @param {String} value The data value of the item to select
1116 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1117 * selected item if it is not currently in view (defaults to true)
1118 * @return {Boolean} True if the value matched an item in the list, else false
1120 selectByValue : function(v, scrollIntoView){
1121 if(!Ext.isEmpty(v, true)){
1122 var r = this.findRecord(this.valueField || this.displayField, v);
1124 this.select(this.store.indexOf(r), scrollIntoView);
1131 <div id="method-Ext.form.ComboBox-select"></div>/**
1132 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1133 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1134 * @param {Number} index The zero-based index of the list item to select
1135 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1136 * selected item if it is not currently in view (defaults to true)
1138 select : function(index, scrollIntoView){
1139 this.selectedIndex = index;
1140 this.view.select(index);
1141 if(scrollIntoView !== false){
1142 var el = this.view.getNode(index);
1144 this.innerList.scrollChildIntoView(el, false);
1151 selectNext : function(){
1152 var ct = this.store.getCount();
1154 if(this.selectedIndex == -1){
1156 }else if(this.selectedIndex < ct-1){
1157 this.select(this.selectedIndex+1);
1163 selectPrev : function(){
1164 var ct = this.store.getCount();
1166 if(this.selectedIndex == -1){
1168 }else if(this.selectedIndex !== 0){
1169 this.select(this.selectedIndex-1);
1175 onKeyUp : function(e){
1177 if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
1180 this.dqTask.delay(this.queryDelay);
1182 Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
1186 validateBlur : function(){
1187 return !this.list || !this.list.isVisible();
1191 initQuery : function(){
1192 this.doQuery(this.getRawValue());
1196 beforeBlur : function(){
1201 postBlur : function(){
1202 Ext.form.ComboBox.superclass.postBlur.call(this);
1204 this.inKeyMode = false;
1207 <div id="method-Ext.form.ComboBox-doQuery"></div>/**
1208 * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
1209 * query allowing the query action to be canceled if needed.
1210 * @param {String} query The SQL query to execute
1211 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1212 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
1213 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1215 doQuery : function(q, forceAll){
1216 q = Ext.isEmpty(q) ? '' : q;
1223 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1227 forceAll = qe.forceAll;
1228 if(forceAll === true || (q.length >= this.minChars)){
1229 if(this.lastQuery !== q){
1231 if(this.mode == 'local'){
1232 this.selectedIndex = -1;
1234 this.store.clearFilter();
1236 this.store.filter(this.displayField, q);
1240 this.store.baseParams[this.queryParam] = q;
1242 params: this.getParams(q)
1247 this.selectedIndex = -1;
1254 getParams : function(q){
1256 //p[this.queryParam] = q;
1259 p.limit = this.pageSize;
1264 <div id="method-Ext.form.ComboBox-collapse"></div>/**
1265 * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
1267 collapse : function(){
1268 if(!this.isExpanded()){
1272 Ext.getDoc().un('mousewheel', this.collapseIf, this);
1273 Ext.getDoc().un('mousedown', this.collapseIf, this);
1274 this.fireEvent('collapse', this);
1278 collapseIf : function(e){
1279 if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
1284 <div id="method-Ext.form.ComboBox-expand"></div>/**
1285 * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
1287 expand : function(){
1288 if(this.isExpanded() || !this.hasFocus){
1292 if(this.title || this.pageSize){
1293 this.assetHeight = 0;
1295 this.assetHeight += this.header.getHeight();
1298 this.assetHeight += this.footer.getHeight();
1302 if(this.bufferSize){
1303 this.doResize(this.bufferSize);
1304 delete this.bufferSize;
1306 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1308 // zindex can change, re-check it and set it if necessary
1309 var listParent = Ext.getDom(this.getListParent() || Ext.getBody()),
1310 zindex = parseInt(Ext.fly(listParent).getStyle('z-index') ,10);
1312 zindex = this.getParentZIndex();
1315 this.list.setZIndex(zindex + 5);
1319 this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
1321 this.mon(Ext.getDoc(), {
1323 mousewheel: this.collapseIf,
1324 mousedown: this.collapseIf
1326 this.fireEvent('expand', this);
1329 <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
1330 * @method onTriggerClick
1334 // Implements the default empty TriggerField.onTriggerClick function
1335 onTriggerClick : function(){
1336 if(this.readOnly || this.disabled){
1339 if(this.isExpanded()){
1344 if(this.triggerAction == 'all') {
1345 this.doQuery(this.allQuery, true);
1347 this.doQuery(this.getRawValue());
1353 <div id="method-Ext.form.ComboBox-autoSize"></div>/**
1357 <div id="cfg-Ext.form.ComboBox-grow"></div>/**
1358 * @cfg {Boolean} grow @hide
1360 <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
1361 * @cfg {Number} growMin @hide
1363 <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
1364 * @cfg {Number} growMax @hide
1368 Ext.reg('combo', Ext.form.ComboBox);