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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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}.
158 <div id="cfg-Ext.form.ComboBox-hiddenId"></div>/**
159 * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
160 * to give the hidden field a unique id. The <tt>hiddenId</tt> and combo {@link Ext.Component#id id} should be
161 * different, since no two DOM nodes should share the same id.
163 <div id="cfg-Ext.form.ComboBox-hiddenValue"></div>/**
164 * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
165 * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
166 * <tt>{@link Ext.form.Field#value value}</tt>.
168 <div id="cfg-Ext.form.ComboBox-listClass"></div>/**
169 * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
170 * applied the dropdown list element (defaults to '').
173 <div id="cfg-Ext.form.ComboBox-selectedClass"></div>/**
174 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
175 * (defaults to <tt>'x-combo-selected'</tt>)
177 selectedClass : 'x-combo-selected',
178 <div id="cfg-Ext.form.ComboBox-listEmptyText"></div>/**
179 * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
183 <div id="cfg-Ext.form.ComboBox-triggerClass"></div>/**
184 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
185 * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
186 * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
188 triggerClass : 'x-form-arrow-trigger',
189 <div id="cfg-Ext.form.ComboBox-shadow"></div>/**
190 * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
191 * 4-way shadow, and <tt>"drop"</tt> for bottom-right
194 <div id="cfg-Ext.form.ComboBox-listAlign"></div>/**
195 * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
196 * on supported anchor positions and offsets. To specify x/y offsets as well, this value
197 * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
198 * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
200 listAlign : 'tl-bl?',
201 <div id="cfg-Ext.form.ComboBox-maxHeight"></div>/**
202 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
203 * (defaults to <tt>300</tt>)
206 <div id="cfg-Ext.form.ComboBox-minHeight"></div>/**
207 * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
208 * distance to the viewport edges (defaults to <tt>90</tt>)
211 <div id="cfg-Ext.form.ComboBox-triggerAction"></div>/**
212 * @cfg {String} triggerAction The action to execute when the trigger is clicked.
213 * <div class="mdetail-params"><ul>
214 * <li><b><tt>'query'</tt></b> : <b>Default</b>
215 * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
216 * <li><b><tt>'all'</tt></b> :
217 * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
219 * <p>See also <code>{@link #queryParam}</code>.</p>
221 triggerAction : 'query',
222 <div id="cfg-Ext.form.ComboBox-minChars"></div>/**
223 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
224 * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
225 * <tt>{@link #mode} = 'local'</tt>, does not apply if
226 * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
229 <div id="cfg-Ext.form.ComboBox-autoSelect"></div>/**
230 * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
231 * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
232 * unless the value of ({@link #typeAheadDelay}) were true.
235 <div id="cfg-Ext.form.ComboBox-typeAhead"></div>/**
236 * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
237 * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
241 <div id="cfg-Ext.form.ComboBox-queryDelay"></div>/**
242 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
243 * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
244 * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
247 <div id="cfg-Ext.form.ComboBox-pageSize"></div>/**
248 * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
249 * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
250 * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
251 * (defaults to <tt>0</tt>).
254 <div id="cfg-Ext.form.ComboBox-selectOnFocus"></div>/**
255 * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
256 * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
259 selectOnFocus : false,
260 <div id="cfg-Ext.form.ComboBox-queryParam"></div>/**
261 * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
262 * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
264 queryParam : 'query',
265 <div id="cfg-Ext.form.ComboBox-loadingText"></div>/**
266 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
267 * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
269 loadingText : 'Loading...',
270 <div id="cfg-Ext.form.ComboBox-resizable"></div>/**
271 * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
272 * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
273 * Defaults to <tt>false</tt>.
276 <div id="cfg-Ext.form.ComboBox-handleHeight"></div>/**
277 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
278 * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
281 <div id="cfg-Ext.form.ComboBox-allQuery"></div>/**
282 * @cfg {String} allQuery The text query to send to the server to return all records for the list
283 * with no filtering (defaults to '')
286 <div id="cfg-Ext.form.ComboBox-mode"></div>/**
287 * @cfg {String} mode Acceptable values are:
288 * <div class="mdetail-params"><ul>
289 * <li><b><tt>'remote'</tt></b> : <b>Default</b>
290 * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
291 * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
292 * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
293 * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
294 * <li><b><tt>'local'</tt></b> :
295 * <p class="sub-desc">ComboBox loads local data</p>
297 var combo = new Ext.form.ComboBox({
298 renderTo: document.body,
300 store: new Ext.data.ArrayStore({
303 'myId', // numeric value is the key
306 data: [[1, 'item1'], [2, 'item2']] // data is local
309 displayField: 'displayText',
316 <div id="cfg-Ext.form.ComboBox-minListWidth"></div>/**
317 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
318 * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
321 <div id="cfg-Ext.form.ComboBox-forceSelection"></div>/**
322 * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
323 * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
325 forceSelection : false,
326 <div id="cfg-Ext.form.ComboBox-typeAheadDelay"></div>/**
327 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
328 * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
330 typeAheadDelay : 250,
331 <div id="cfg-Ext.form.ComboBox-valueNotFoundText"></div>/**
332 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
333 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
334 * default text is used, it means there is no value set and no validation will occur on this field.
337 <div id="cfg-Ext.form.ComboBox-lazyInit"></div>/**
338 * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
339 * (defaults to <tt>true</tt>)
343 <div id="cfg-Ext.form.ComboBox-clearFilterOnReset"></div>/**
344 * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
345 * (defaults to <tt>true</tt>)
347 clearFilterOnReset : true,
349 <div id="cfg-Ext.form.ComboBox-submitValue"></div>/**
350 * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
351 * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
352 * Defaults to <tt>undefined</tt>.
354 submitValue: undefined,
356 <div id="prop-Ext.form.ComboBox-lastQuery"></div>/**
357 * The value of the match string used to filter the store. Delete this property to force a requery.
360 var combo = new Ext.form.ComboBox({
365 // delete the previous query in the beforequery event or set
366 // combo.lastQuery = null (this will reload the store the next time it expands)
367 beforequery: function(qe){
368 delete qe.combo.lastQuery;
373 * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
374 * configure the combo with <tt>lastQuery=''</tt>. Example use:
376 var combo = new Ext.form.ComboBox({
379 triggerAction: 'all',
383 * @property lastQuery
388 initComponent : function(){
389 Ext.form.ComboBox.superclass.initComponent.call(this);
391 <div id="event-Ext.form.ComboBox-expand"></div>/**
393 * Fires when the dropdown list is expanded
394 * @param {Ext.form.ComboBox} combo This combo box
397 <div id="event-Ext.form.ComboBox-collapse"></div>/**
399 * Fires when the dropdown list is collapsed
400 * @param {Ext.form.ComboBox} combo This combo box
404 <div id="event-Ext.form.ComboBox-beforeselect"></div>/**
405 * @event beforeselect
406 * Fires before a list item is selected. Return false to cancel the selection.
407 * @param {Ext.form.ComboBox} combo This combo box
408 * @param {Ext.data.Record} record The data record returned from the underlying store
409 * @param {Number} index The index of the selected item in the dropdown list
412 <div id="event-Ext.form.ComboBox-select"></div>/**
414 * Fires when a list item is selected
415 * @param {Ext.form.ComboBox} combo This combo box
416 * @param {Ext.data.Record} record The data record returned from the underlying store
417 * @param {Number} index The index of the selected item in the dropdown list
420 <div id="event-Ext.form.ComboBox-beforequery"></div>/**
422 * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
423 * cancel property to true.
424 * @param {Object} queryEvent An object that has these properties:<ul>
425 * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
426 * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
427 * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
428 * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
434 var s = Ext.getDom(this.transform);
435 if(!this.hiddenName){
436 this.hiddenName = s.name;
440 var d = [], opts = s.options;
441 for(var i = 0, len = opts.length;i < len; i++){
443 value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
444 if(o.selected && Ext.isEmpty(this.value, true)) {
447 d.push([value, o.text]);
449 this.store = new Ext.data.ArrayStore({
451 fields: ['value', 'text'],
455 this.valueField = 'value';
456 this.displayField = 'text';
458 s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
459 if(!this.lazyRender){
461 this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
462 this.render(this.el.parentNode, s);
466 //auto-configure store from local array data
468 this.store = Ext.StoreMgr.lookup(this.store);
469 if(this.store.autoCreated){
470 this.displayField = this.valueField = 'field1';
471 if(!this.store.expandData){
472 this.displayField = 'field2';
478 this.selectedIndex = -1;
479 if(this.mode == 'local'){
480 if(!Ext.isDefined(this.initialConfig.queryDelay)){
481 this.queryDelay = 10;
483 if(!Ext.isDefined(this.initialConfig.minChars)){
490 onRender : function(ct, position){
491 if(this.hiddenName && !Ext.isDefined(this.submitValue)){
492 this.submitValue = false;
494 Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
496 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
497 id: (this.hiddenId || Ext.id())}, 'before', true);
501 this.el.dom.setAttribute('autocomplete', 'off');
507 this.on('focus', this.initList, this, {single: true});
512 initValue : function(){
513 Ext.form.ComboBox.superclass.initValue.call(this);
514 if(this.hiddenField){
515 this.hiddenField.value =
516 Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
520 getParentZIndex : function(){
523 this.findParentBy(function(ct){
524 zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
531 getZIndex : function(listParent){
532 listParent = listParent || Ext.getDom(this.getListParent() || Ext.getBody());
533 var zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10);
535 zindex = this.getParentZIndex();
537 return (zindex || 12000) + 5;
541 initList : function(){
543 var cls = 'x-combo-list',
544 listParent = Ext.getDom(this.getListParent() || Ext.getBody());
546 this.list = new Ext.Layer({
547 parentEl: listParent,
549 cls: [cls, this.listClass].join(' '),
551 zindex: this.getZIndex(listParent)
554 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
555 this.list.setSize(lw, 0);
556 this.list.swallowEvent('mousewheel');
557 this.assetHeight = 0;
558 if(this.syncFont !== false){
559 this.list.setStyle('font-size', this.el.getStyle('font-size'));
562 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
563 this.assetHeight += this.header.getHeight();
566 this.innerList = this.list.createChild({cls:cls+'-inner'});
567 this.mon(this.innerList, 'mouseover', this.onViewOver, this);
568 this.mon(this.innerList, 'mousemove', this.onViewMove, this);
569 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
572 this.footer = this.list.createChild({cls:cls+'-ft'});
573 this.pageTb = new Ext.PagingToolbar({
575 pageSize: this.pageSize,
578 this.assetHeight += this.footer.getHeight();
582 <div id="cfg-Ext.form.ComboBox-tpl"></div>/**
583 * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
584 * use to display each item in the dropdown list. The dropdown list is displayed in a
585 * DataView. See {@link #view}.</p>
586 * <p>The default template string is:</p><pre><code>
587 '<tpl for="."><div class="x-combo-list-item">{' + this.displayField + '}</div></tpl>'
589 * <p>Override the default value to create custom UI layouts for items in the list.
590 * For example:</p><pre><code>
591 '<tpl for="."><div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>'
593 * <p>The template <b>must</b> contain one or more substitution parameters using field
594 * names from the Combo's</b> {@link #store Store}. In the example above an
595 * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
596 * <p>To preserve the default visual look of list items, add the CSS class name
597 * <pre>x-combo-list-item</pre> to the template's container element.</p>
598 * <p>Also see {@link #itemSelector} for additional details.</p>
600 this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
601 <div id="cfg-Ext.form.ComboBox-itemSelector"></div>/**
602 * @cfg {String} itemSelector
603 * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
604 * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
605 * display will be working with.</p>
606 * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
607 * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
608 * to dropdown list items</b>
612 <div id="prop-Ext.form.ComboBox-view"></div>/**
613 * The {@link Ext.DataView DataView} used to display the ComboBox's options.
616 this.view = new Ext.DataView({
617 applyTo: this.innerList,
620 selectedClass: this.selectedClass,
621 itemSelector: this.itemSelector || '.' + cls + '-item',
622 emptyText: this.listEmptyText,
623 deferEmptyText: false
626 this.mon(this.view, {
627 containerclick : this.onViewClick,
628 click : this.onViewClick,
632 this.bindStore(this.store, true);
635 this.resizer = new Ext.Resizable(this.list, {
636 pinned:true, handles:'se'
638 this.mon(this.resizer, 'resize', function(r, w, h){
639 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
641 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
642 this.restrictHeight();
645 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
650 <div id="method-Ext.form.ComboBox-getListParent"></div>/**
651 * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
652 * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
653 * to a different Element. An example might be rendering the list inside a Menu so that clicking
654 * the list does not hide the Menu:<pre><code>
655 var store = new Ext.data.ArrayStore({
657 fields: ['initials', 'fullname'],
659 ['FF', 'Fred Flintstone'],
660 ['BR', 'Barney Rubble']
664 var combo = new Ext.form.ComboBox({
666 displayField: 'fullname',
667 emptyText: 'Select a name...',
668 forceSelection: true,
669 getListParent: function() {
670 return this.el.up('.x-menu');
672 iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
675 triggerAction: 'all',
680 var menu = new Ext.menu.Menu({
683 combo // A Field in a Menu
688 getListParent : function() {
689 return document.body;
692 <div id="method-Ext.form.ComboBox-getStore"></div>/**
693 * Returns the store associated with this combo.
694 * @return {Ext.data.Store} The store
696 getStore : function(){
701 bindStore : function(store, initial){
702 if(this.store && !initial){
703 if(this.store !== store && this.store.autoDestroy){
704 this.store.destroy();
706 this.store.un('beforeload', this.onBeforeLoad, this);
707 this.store.un('load', this.onLoad, this);
708 this.store.un('exception', this.collapse, this);
713 this.view.bindStore(null);
716 this.pageTb.bindStore(null);
722 this.lastQuery = null;
724 this.pageTb.bindStore(store);
728 this.store = Ext.StoreMgr.lookup(store);
731 beforeload: this.onBeforeLoad,
733 exception: this.collapse
737 this.view.bindStore(store);
743 if(this.clearFilterOnReset && this.mode == 'local'){
744 this.store.clearFilter();
746 Ext.form.ComboBox.superclass.reset.call(this);
750 initEvents : function(){
751 Ext.form.ComboBox.superclass.initEvents.call(this);
753 <div id="prop-Ext.form.ComboBox-keyNav"></div>/**
756 * <p>A {@link Ext.KeyNav KeyNav} object which handles navigation keys for this ComboBox. This performs actions
757 * based on keystrokes typed when the input field is focused.</p>
758 * <p><b>After the ComboBox has been rendered</b>, you may override existing navigation key functionality,
759 * or add your own based upon key names as specified in the {@link Ext.KeyNav KeyNav} class.</p>
760 * <p>The function is executed in the scope (<code>this</code> reference of the ComboBox. Example:</p><pre><code>
761 myCombo.keyNav.esc = function(e) { // Override ESC handling function
762 this.collapse(); // Standard behaviour of Ext's ComboBox.
763 this.setValue(this.startValue); // We reset to starting value on ESC
765 myCombo.keyNav.tab = function() { // Override TAB handling function
766 this.onViewClick(false); // Select the currently highlighted row
770 this.keyNav = new Ext.KeyNav(this.el, {
772 this.inKeyMode = true;
776 "down" : function(e){
777 if(!this.isExpanded()){
778 this.onTriggerClick();
780 this.inKeyMode = true;
785 "enter" : function(e){
794 if (this.forceSelection === true) {
797 this.onViewClick(false);
804 doRelay : function(e, h, hname){
805 if(hname == 'down' || this.scope.isExpanded()){
806 // this MUST be called before ComboBox#fireKey()
807 var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
808 if(!Ext.isIE && Ext.EventManager.useKeydown){
809 // call Combo#fireKey() for browsers which use keydown event (except IE)
810 this.scope.fireKey(e);
818 defaultEventAction: 'stopEvent'
820 this.queryDelay = Math.max(this.queryDelay || 10,
821 this.mode == 'local' ? 10 : 250);
822 this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
824 this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
826 if(!this.enableKeyEvents){
827 this.mon(this.el, 'keyup', this.onKeyUp, this);
833 onDestroy : function(){
835 this.dqTask.cancel();
838 this.bindStore(null);
845 Ext.destroyMembers(this, 'hiddenField');
846 Ext.form.ComboBox.superclass.onDestroy.call(this);
850 fireKey : function(e){
851 if (!this.isExpanded()) {
852 Ext.form.ComboBox.superclass.fireKey.call(this, e);
857 onResize : function(w, h){
858 Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
859 if(!isNaN(w) && this.isVisible() && this.list){
866 doResize: function(w){
867 if(!Ext.isDefined(this.listWidth)){
868 var lw = Math.max(w, this.minListWidth);
869 this.list.setWidth(lw);
870 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
875 onEnable : function(){
876 Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
877 if(this.hiddenField){
878 this.hiddenField.disabled = false;
883 onDisable : function(){
884 Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
885 if(this.hiddenField){
886 this.hiddenField.disabled = true;
891 onBeforeLoad : function(){
895 this.innerList.update(this.loadingText ?
896 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
897 this.restrictHeight();
898 this.selectedIndex = -1;
906 if(this.store.getCount() > 0 || this.listEmptyText){
908 this.restrictHeight();
909 if(this.lastQuery == this.allQuery){
911 this.el.dom.select();
914 if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
915 this.select(0, true);
918 if(this.autoSelect !== false){
921 if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
922 this.taTask.delay(this.typeAheadDelay);
932 onTypeAhead : function(){
933 if(this.store.getCount() > 0){
934 var r = this.store.getAt(0);
935 var newValue = r.data[this.displayField];
936 var len = newValue.length;
937 var selStart = this.getRawValue().length;
939 this.setRawValue(newValue);
940 this.selectText(selStart, newValue.length);
946 assertValue : function(){
947 var val = this.getRawValue(),
950 if(this.valueField && Ext.isDefined(this.value)){
951 rec = this.findRecord(this.valueField, this.value);
953 if(!rec || rec.get(this.displayField) != val){
954 rec = this.findRecord(this.displayField, val);
956 if(!rec && this.forceSelection){
957 if(val.length > 0 && val != this.emptyText){
958 this.el.dom.value = Ext.value(this.lastSelectionText, '');
959 this.applyEmptyText();
964 if(rec && this.valueField){
965 // onSelect may have already set the value and by doing so
966 // set the display field properly. Let's not wipe out the
967 // valueField here by just sending the displayField.
968 if (this.value == val){
971 val = rec.get(this.valueField || this.displayField);
978 onSelect : function(record, index){
979 if(this.fireEvent('beforeselect', this, record, index) !== false){
980 this.setValue(record.data[this.valueField || this.displayField]);
982 this.fireEvent('select', this, record, index);
988 var hf = this.hiddenField;
989 return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
992 <div id="method-Ext.form.ComboBox-getValue"></div>/**
993 * Returns the currently selected field value or empty string if no value is set.
994 * @return {String} value The selected value
996 getValue : function(){
998 return Ext.isDefined(this.value) ? this.value : '';
1000 return Ext.form.ComboBox.superclass.getValue.call(this);
1004 <div id="method-Ext.form.ComboBox-clearValue"></div>/**
1005 * Clears any text/value currently set in the field
1007 clearValue : function(){
1008 if(this.hiddenField){
1009 this.hiddenField.value = '';
1011 this.setRawValue('');
1012 this.lastSelectionText = '';
1013 this.applyEmptyText();
1017 <div id="method-Ext.form.ComboBox-setValue"></div>/**
1018 * Sets the specified value into the field. If the value finds a match, the corresponding record text
1019 * will be displayed in the field. If the value does not match the data value of an existing item,
1020 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
1021 * Otherwise the field will be blank (although the value will still be set).
1022 * @param {String} value The value to match
1023 * @return {Ext.form.Field} this
1025 setValue : function(v){
1027 if(this.valueField){
1028 var r = this.findRecord(this.valueField, v);
1030 text = r.data[this.displayField];
1031 }else if(Ext.isDefined(this.valueNotFoundText)){
1032 text = this.valueNotFoundText;
1035 this.lastSelectionText = text;
1036 if(this.hiddenField){
1037 this.hiddenField.value = Ext.value(v, '');
1039 Ext.form.ComboBox.superclass.setValue.call(this, text);
1045 findRecord : function(prop, value){
1047 if(this.store.getCount() > 0){
1048 this.store.each(function(r){
1049 if(r.data[prop] == value){
1059 onViewMove : function(e, t){
1060 this.inKeyMode = false;
1064 onViewOver : function(e, t){
1065 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1068 var item = this.view.findItemFromChild(t);
1070 var index = this.view.indexOf(item);
1071 this.select(index, false);
1076 onViewClick : function(doFocus){
1077 var index = this.view.getSelectedIndexes()[0],
1081 this.onSelect(r, index);
1085 if(doFocus !== false){
1092 restrictHeight : function(){
1093 this.innerList.dom.style.height = '';
1094 var inner = this.innerList.dom,
1095 pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
1096 h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
1097 ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
1098 hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
1099 space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
1101 h = Math.min(h, space, this.maxHeight);
1103 this.innerList.setHeight(h);
1104 this.list.beginUpdate();
1105 this.list.setHeight(h+pad);
1106 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1107 this.list.endUpdate();
1110 <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
1111 * Returns true if the dropdown list is expanded, else false.
1113 isExpanded : function(){
1114 return this.list && this.list.isVisible();
1117 <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
1118 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1119 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1120 * @param {String} value The data value of the item to select
1121 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1122 * selected item if it is not currently in view (defaults to true)
1123 * @return {Boolean} True if the value matched an item in the list, else false
1125 selectByValue : function(v, scrollIntoView){
1126 if(!Ext.isEmpty(v, true)){
1127 var r = this.findRecord(this.valueField || this.displayField, v);
1129 this.select(this.store.indexOf(r), scrollIntoView);
1136 <div id="method-Ext.form.ComboBox-select"></div>/**
1137 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1138 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1139 * @param {Number} index The zero-based index of the list item to select
1140 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1141 * selected item if it is not currently in view (defaults to true)
1143 select : function(index, scrollIntoView){
1144 this.selectedIndex = index;
1145 this.view.select(index);
1146 if(scrollIntoView !== false){
1147 var el = this.view.getNode(index);
1149 this.innerList.scrollChildIntoView(el, false);
1156 selectNext : function(){
1157 var ct = this.store.getCount();
1159 if(this.selectedIndex == -1){
1161 }else if(this.selectedIndex < ct-1){
1162 this.select(this.selectedIndex+1);
1168 selectPrev : function(){
1169 var ct = this.store.getCount();
1171 if(this.selectedIndex == -1){
1173 }else if(this.selectedIndex !== 0){
1174 this.select(this.selectedIndex-1);
1180 onKeyUp : function(e){
1182 if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
1185 this.dqTask.delay(this.queryDelay);
1187 Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
1191 validateBlur : function(){
1192 return !this.list || !this.list.isVisible();
1196 initQuery : function(){
1197 this.doQuery(this.getRawValue());
1201 beforeBlur : function(){
1206 postBlur : function(){
1207 Ext.form.ComboBox.superclass.postBlur.call(this);
1209 this.inKeyMode = false;
1212 <div id="method-Ext.form.ComboBox-doQuery"></div>/**
1213 * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
1214 * query allowing the query action to be canceled if needed.
1215 * @param {String} query The SQL query to execute
1216 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1217 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
1218 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1220 doQuery : function(q, forceAll){
1221 q = Ext.isEmpty(q) ? '' : q;
1228 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1232 forceAll = qe.forceAll;
1233 if(forceAll === true || (q.length >= this.minChars)){
1234 if(this.lastQuery !== q){
1236 if(this.mode == 'local'){
1237 this.selectedIndex = -1;
1239 this.store.clearFilter();
1241 this.store.filter(this.displayField, q);
1245 this.store.baseParams[this.queryParam] = q;
1247 params: this.getParams(q)
1252 this.selectedIndex = -1;
1259 getParams : function(q){
1261 paramNames = this.store.paramNames;
1263 params[paramNames.start] = 0;
1264 params[paramNames.limit] = this.pageSize;
1269 <div id="method-Ext.form.ComboBox-collapse"></div>/**
1270 * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
1272 collapse : function(){
1273 if(!this.isExpanded()){
1277 Ext.getDoc().un('mousewheel', this.collapseIf, this);
1278 Ext.getDoc().un('mousedown', this.collapseIf, this);
1279 this.fireEvent('collapse', this);
1283 collapseIf : function(e){
1284 if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
1289 <div id="method-Ext.form.ComboBox-expand"></div>/**
1290 * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
1292 expand : function(){
1293 if(this.isExpanded() || !this.hasFocus){
1297 if(this.title || this.pageSize){
1298 this.assetHeight = 0;
1300 this.assetHeight += this.header.getHeight();
1303 this.assetHeight += this.footer.getHeight();
1307 if(this.bufferSize){
1308 this.doResize(this.bufferSize);
1309 delete this.bufferSize;
1311 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1313 // zindex can change, re-check it and set it if necessary
1314 this.list.setZIndex(this.getZIndex());
1317 this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
1319 this.mon(Ext.getDoc(), {
1321 mousewheel: this.collapseIf,
1322 mousedown: this.collapseIf
1324 this.fireEvent('expand', this);
1327 <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
1328 * @method onTriggerClick
1332 // Implements the default empty TriggerField.onTriggerClick function
1333 onTriggerClick : function(){
1334 if(this.readOnly || this.disabled){
1337 if(this.isExpanded()){
1342 if(this.triggerAction == 'all') {
1343 this.doQuery(this.allQuery, true);
1345 this.doQuery(this.getRawValue());
1351 <div id="method-Ext.form.ComboBox-autoSize"></div>/**
1355 <div id="cfg-Ext.form.ComboBox-grow"></div>/**
1356 * @cfg {Boolean} grow @hide
1358 <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
1359 * @cfg {Number} growMin @hide
1361 <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
1362 * @cfg {Number} growMax @hide
1366 Ext.reg('combo', Ext.form.ComboBox);