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.0
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);
755 this.keyNav = new Ext.KeyNav(this.el, {
757 this.inKeyMode = true;
761 "down" : function(e){
762 if(!this.isExpanded()){
763 this.onTriggerClick();
765 this.inKeyMode = true;
770 "enter" : function(e){
779 if (this.forceSelection === true) {
782 this.onViewClick(false);
789 doRelay : function(e, h, hname){
790 if(hname == 'down' || this.scope.isExpanded()){
791 // this MUST be called before ComboBox#fireKey()
792 var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
793 if(!Ext.isIE && Ext.EventManager.useKeydown){
794 // call Combo#fireKey() for browsers which use keydown event (except IE)
795 this.scope.fireKey(e);
803 defaultEventAction: 'stopEvent'
805 this.queryDelay = Math.max(this.queryDelay || 10,
806 this.mode == 'local' ? 10 : 250);
807 this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
809 this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
811 if(!this.enableKeyEvents){
812 this.mon(this.el, 'keyup', this.onKeyUp, this);
818 onDestroy : function(){
820 this.dqTask.cancel();
823 this.bindStore(null);
830 Ext.destroyMembers(this, 'hiddenField');
831 Ext.form.ComboBox.superclass.onDestroy.call(this);
835 fireKey : function(e){
836 if (!this.isExpanded()) {
837 Ext.form.ComboBox.superclass.fireKey.call(this, e);
842 onResize : function(w, h){
843 Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
844 if(!isNaN(w) && this.isVisible() && this.list){
851 doResize: function(w){
852 if(!Ext.isDefined(this.listWidth)){
853 var lw = Math.max(w, this.minListWidth);
854 this.list.setWidth(lw);
855 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
860 onEnable : function(){
861 Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
862 if(this.hiddenField){
863 this.hiddenField.disabled = false;
868 onDisable : function(){
869 Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
870 if(this.hiddenField){
871 this.hiddenField.disabled = true;
876 onBeforeLoad : function(){
880 this.innerList.update(this.loadingText ?
881 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
882 this.restrictHeight();
883 this.selectedIndex = -1;
891 if(this.store.getCount() > 0 || this.listEmptyText){
893 this.restrictHeight();
894 if(this.lastQuery == this.allQuery){
896 this.el.dom.select();
899 if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
900 this.select(0, true);
903 if(this.autoSelect !== false){
906 if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
907 this.taTask.delay(this.typeAheadDelay);
917 onTypeAhead : function(){
918 if(this.store.getCount() > 0){
919 var r = this.store.getAt(0);
920 var newValue = r.data[this.displayField];
921 var len = newValue.length;
922 var selStart = this.getRawValue().length;
924 this.setRawValue(newValue);
925 this.selectText(selStart, newValue.length);
931 assertValue : function(){
932 var val = this.getRawValue(),
933 rec = this.findRecord(this.displayField, val);
935 if(!rec && this.forceSelection){
936 if(val.length > 0 && val != this.emptyText){
937 this.el.dom.value = Ext.value(this.lastSelectionText, '');
938 this.applyEmptyText();
944 // onSelect may have already set the value and by doing so
945 // set the display field properly. Let's not wipe out the
946 // valueField here by just sending the displayField.
947 if (val == rec.get(this.displayField) && this.value == rec.get(this.valueField)){
950 val = rec.get(this.valueField || this.displayField);
957 onSelect : function(record, index){
958 if(this.fireEvent('beforeselect', this, record, index) !== false){
959 this.setValue(record.data[this.valueField || this.displayField]);
961 this.fireEvent('select', this, record, index);
967 var hf = this.hiddenField;
968 return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
971 <div id="method-Ext.form.ComboBox-getValue"></div>/**
972 * Returns the currently selected field value or empty string if no value is set.
973 * @return {String} value The selected value
975 getValue : function(){
977 return Ext.isDefined(this.value) ? this.value : '';
979 return Ext.form.ComboBox.superclass.getValue.call(this);
983 <div id="method-Ext.form.ComboBox-clearValue"></div>/**
984 * Clears any text/value currently set in the field
986 clearValue : function(){
987 if(this.hiddenField){
988 this.hiddenField.value = '';
990 this.setRawValue('');
991 this.lastSelectionText = '';
992 this.applyEmptyText();
996 <div id="method-Ext.form.ComboBox-setValue"></div>/**
997 * Sets the specified value into the field. If the value finds a match, the corresponding record text
998 * will be displayed in the field. If the value does not match the data value of an existing item,
999 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1000 * Otherwise the field will be blank (although the value will still be set).
1001 * @param {String} value The value to match
1002 * @return {Ext.form.Field} this
1004 setValue : function(v){
1006 if(this.valueField){
1007 var r = this.findRecord(this.valueField, v);
1009 text = r.data[this.displayField];
1010 }else if(Ext.isDefined(this.valueNotFoundText)){
1011 text = this.valueNotFoundText;
1014 this.lastSelectionText = text;
1015 if(this.hiddenField){
1016 this.hiddenField.value = Ext.value(v, '');
1018 Ext.form.ComboBox.superclass.setValue.call(this, text);
1024 findRecord : function(prop, value){
1026 if(this.store.getCount() > 0){
1027 this.store.each(function(r){
1028 if(r.data[prop] == value){
1038 onViewMove : function(e, t){
1039 this.inKeyMode = false;
1043 onViewOver : function(e, t){
1044 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1047 var item = this.view.findItemFromChild(t);
1049 var index = this.view.indexOf(item);
1050 this.select(index, false);
1055 onViewClick : function(doFocus){
1056 var index = this.view.getSelectedIndexes()[0],
1060 this.onSelect(r, index);
1064 if(doFocus !== false){
1071 restrictHeight : function(){
1072 this.innerList.dom.style.height = '';
1073 var inner = this.innerList.dom,
1074 pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
1075 h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
1076 ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
1077 hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
1078 space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
1080 h = Math.min(h, space, this.maxHeight);
1082 this.innerList.setHeight(h);
1083 this.list.beginUpdate();
1084 this.list.setHeight(h+pad);
1085 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1086 this.list.endUpdate();
1089 <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
1090 * Returns true if the dropdown list is expanded, else false.
1092 isExpanded : function(){
1093 return this.list && this.list.isVisible();
1096 <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
1097 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1098 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1099 * @param {String} value The data value of the item to select
1100 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1101 * selected item if it is not currently in view (defaults to true)
1102 * @return {Boolean} True if the value matched an item in the list, else false
1104 selectByValue : function(v, scrollIntoView){
1105 if(!Ext.isEmpty(v, true)){
1106 var r = this.findRecord(this.valueField || this.displayField, v);
1108 this.select(this.store.indexOf(r), scrollIntoView);
1115 <div id="method-Ext.form.ComboBox-select"></div>/**
1116 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1117 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1118 * @param {Number} index The zero-based index of the list item to select
1119 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1120 * selected item if it is not currently in view (defaults to true)
1122 select : function(index, scrollIntoView){
1123 this.selectedIndex = index;
1124 this.view.select(index);
1125 if(scrollIntoView !== false){
1126 var el = this.view.getNode(index);
1128 this.innerList.scrollChildIntoView(el, false);
1135 selectNext : function(){
1136 var ct = this.store.getCount();
1138 if(this.selectedIndex == -1){
1140 }else if(this.selectedIndex < ct-1){
1141 this.select(this.selectedIndex+1);
1147 selectPrev : function(){
1148 var ct = this.store.getCount();
1150 if(this.selectedIndex == -1){
1152 }else if(this.selectedIndex !== 0){
1153 this.select(this.selectedIndex-1);
1159 onKeyUp : function(e){
1161 if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
1164 this.dqTask.delay(this.queryDelay);
1166 Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
1170 validateBlur : function(){
1171 return !this.list || !this.list.isVisible();
1175 initQuery : function(){
1176 this.doQuery(this.getRawValue());
1180 beforeBlur : function(){
1185 postBlur : function(){
1186 Ext.form.ComboBox.superclass.postBlur.call(this);
1188 this.inKeyMode = false;
1191 <div id="method-Ext.form.ComboBox-doQuery"></div>/**
1192 * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
1193 * query allowing the query action to be canceled if needed.
1194 * @param {String} query The SQL query to execute
1195 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1196 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
1197 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1199 doQuery : function(q, forceAll){
1200 q = Ext.isEmpty(q) ? '' : q;
1207 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1211 forceAll = qe.forceAll;
1212 if(forceAll === true || (q.length >= this.minChars)){
1213 if(this.lastQuery !== q){
1215 if(this.mode == 'local'){
1216 this.selectedIndex = -1;
1218 this.store.clearFilter();
1220 this.store.filter(this.displayField, q);
1224 this.store.baseParams[this.queryParam] = q;
1226 params: this.getParams(q)
1231 this.selectedIndex = -1;
1238 getParams : function(q){
1240 //p[this.queryParam] = q;
1243 p.limit = this.pageSize;
1248 <div id="method-Ext.form.ComboBox-collapse"></div>/**
1249 * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
1251 collapse : function(){
1252 if(!this.isExpanded()){
1256 Ext.getDoc().un('mousewheel', this.collapseIf, this);
1257 Ext.getDoc().un('mousedown', this.collapseIf, this);
1258 this.fireEvent('collapse', this);
1262 collapseIf : function(e){
1263 if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
1268 <div id="method-Ext.form.ComboBox-expand"></div>/**
1269 * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
1271 expand : function(){
1272 if(this.isExpanded() || !this.hasFocus){
1276 if(this.title || this.pageSize){
1277 this.assetHeight = 0;
1279 this.assetHeight += this.header.getHeight();
1282 this.assetHeight += this.footer.getHeight();
1286 if(this.bufferSize){
1287 this.doResize(this.bufferSize);
1288 delete this.bufferSize;
1290 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1292 // zindex can change, re-check it and set it if necessary
1293 var listParent = Ext.getDom(this.getListParent() || Ext.getBody()),
1294 zindex = parseInt(Ext.fly(listParent).getStyle('z-index') ,10);
1296 zindex = this.getParentZIndex();
1299 this.list.setZIndex(zindex + 5);
1303 this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
1305 this.mon(Ext.getDoc(), {
1307 mousewheel: this.collapseIf,
1308 mousedown: this.collapseIf
1310 this.fireEvent('expand', this);
1313 <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
1314 * @method onTriggerClick
1318 // Implements the default empty TriggerField.onTriggerClick function
1319 onTriggerClick : function(){
1320 if(this.readOnly || this.disabled){
1323 if(this.isExpanded()){
1328 if(this.triggerAction == 'all') {
1329 this.doQuery(this.allQuery, true);
1331 this.doQuery(this.getRawValue());
1337 <div id="method-Ext.form.ComboBox-autoSize"></div>/**
1341 <div id="cfg-Ext.form.ComboBox-grow"></div>/**
1342 * @cfg {Boolean} grow @hide
1344 <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
1345 * @cfg {Number} growMin @hide
1347 <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
1348 * @cfg {Number} growMax @hide
1352 Ext.reg('combo', Ext.form.ComboBox);