3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.form.ComboBox"></div>/**
10 * @class Ext.form.ComboBox
11 * @extends Ext.form.TriggerField
12 * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
13 * <p>A ComboBox works in a similar manner to a traditional HTML <select> field. The difference is
14 * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
15 * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
16 * which is named according to the {@link #name}.</p>
17 * <p><b><u>Events</u></b></p>
18 * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
19 var cb = new Ext.form.ComboBox({
20 // all of your config options
23 'select': yourFunction
27 // Alternatively, you can assign events after the object is created:
28 var cb = new Ext.form.ComboBox(yourOptions);
29 cb.on('select', yourFunction, yourScope);
32 * <p><b><u>ComboBox in Grid</u></b></p>
33 * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
34 * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
35 * a reusable render, for example:<pre><code>
36 // create reusable renderer
37 Ext.util.Format.comboRenderer = function(combo){
38 return function(value){
39 var record = combo.findRecord(combo.{@link #valueField}, value);
40 return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
44 // create the combo instance
45 var combo = new Ext.form.ComboBox({
46 {@link #typeAhead}: true,
47 {@link #triggerAction}: 'all',
48 {@link #lazyRender}:true,
49 {@link #mode}: 'local',
50 {@link #store}: new Ext.data.ArrayStore({
56 data: [[1, 'item1'], [2, 'item2']]
58 {@link #valueField}: 'myId',
59 {@link #displayField}: 'displayText'
62 // snippet of column model used within grid
63 var cm = new Ext.grid.ColumnModel([{
66 header: "Some Header",
67 dataIndex: 'whatever',
69 editor: combo, // specify reference to combo instance
70 renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
76 * <p><b><u>Filtering</u></b></p>
77 * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
78 * store manually see <tt>{@link #lastQuery}</tt>.</p>
80 * Create a new ComboBox.
81 * @param {Object} config Configuration options
84 Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
85 <div id="cfg-Ext.form.ComboBox-transform"></div>/**
86 * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
87 * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
88 * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
90 <div id="cfg-Ext.form.ComboBox-lazyRender"></div>/**
91 * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
92 * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
93 * defaults to <tt>false</tt>).
95 <div id="cfg-Ext.form.ComboBox-autoCreate"></div>/**
96 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
97 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
98 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
99 * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
101 <div id="cfg-Ext.form.ComboBox-store"></div>/**
102 * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
103 * Acceptable values for this property are:
104 * <div class="mdetail-params"><ul>
105 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
106 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally,
107 * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
108 * <div class="mdetail-params"><ul>
109 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
110 * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
111 * {@link #valueField} and {@link #displayField})</div></li>
112 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
113 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
114 * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
115 * </div></li></ul></div></li></ul></div>
116 * <p>See also <tt>{@link #mode}</tt>.</p>
118 <div id="cfg-Ext.form.ComboBox-title"></div>/**
119 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
120 * the dropdown list (defaults to undefined, with no header element)
124 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
125 <div id="cfg-Ext.form.ComboBox-listWidth"></div>/**
126 * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
127 * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}
129 <div id="cfg-Ext.form.ComboBox-displayField"></div>/**
130 * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
131 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field1'</tt> if
132 * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
133 * the store configuration}).
134 * <p>See also <tt>{@link #valueField}</tt>.</p>
135 * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
136 * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
139 <div id="cfg-Ext.form.ComboBox-valueField"></div>/**
140 * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
141 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field2'</tt> if
142 * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
143 * the store configuration}).
144 * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
145 * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
147 <div id="cfg-Ext.form.ComboBox-hiddenName"></div>/**
148 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
149 * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
150 * post during a form submission. See also {@link #valueField}.
151 * <p><b>Note</b>: the hidden field's id will also default to this name if {@link #hiddenId} is not specified.
152 * The ComboBox {@link Ext.Component#id id} and the <tt>{@link #hiddenId}</tt> <b>should be different</b>, since
153 * no two DOM nodes should share the same id. So, if the ComboBox <tt>{@link Ext.form.Field#name name}</tt> and
154 * <tt>hiddenName</tt> are the same, you should specify a unique <tt>{@link #hiddenId}</tt>.</p>
156 <div id="cfg-Ext.form.ComboBox-hiddenId"></div>/**
157 * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
158 * to give the hidden field a unique id (defaults to the <tt>{@link #hiddenName}</tt>). The <tt>hiddenId</tt>
159 * and combo {@link Ext.Component#id id} should be different, since no two DOM
160 * nodes should share the same id.
162 <div id="cfg-Ext.form.ComboBox-hiddenValue"></div>/**
163 * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
164 * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
165 * <tt>{@link Ext.form.Field#value value}</tt>.
167 <div id="cfg-Ext.form.ComboBox-listClass"></div>/**
168 * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
169 * applied the dropdown list element (defaults to '').
172 <div id="cfg-Ext.form.ComboBox-selectedClass"></div>/**
173 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
174 * (defaults to <tt>'x-combo-selected'</tt>)
176 selectedClass : 'x-combo-selected',
177 <div id="cfg-Ext.form.ComboBox-listEmptyText"></div>/**
178 * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
182 <div id="cfg-Ext.form.ComboBox-triggerClass"></div>/**
183 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
184 * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
185 * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
187 triggerClass : 'x-form-arrow-trigger',
188 <div id="cfg-Ext.form.ComboBox-shadow"></div>/**
189 * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
190 * 4-way shadow, and <tt>"drop"</tt> for bottom-right
193 <div id="cfg-Ext.form.ComboBox-listAlign"></div>/**
194 * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
195 * on supported anchor positions and offsets. To specify x/y offsets as well, this value
196 * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
197 * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
199 listAlign : 'tl-bl?',
200 <div id="cfg-Ext.form.ComboBox-maxHeight"></div>/**
201 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
202 * (defaults to <tt>300</tt>)
205 <div id="cfg-Ext.form.ComboBox-minHeight"></div>/**
206 * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
207 * distance to the viewport edges (defaults to <tt>90</tt>)
210 <div id="cfg-Ext.form.ComboBox-triggerAction"></div>/**
211 * @cfg {String} triggerAction The action to execute when the trigger is clicked.
212 * <div class="mdetail-params"><ul>
213 * <li><b><tt>'query'</tt></b> : <b>Default</b>
214 * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
215 * <li><b><tt>'all'</tt></b> :
216 * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
218 * <p>See also <code>{@link #queryParam}</code>.</p>
220 triggerAction : 'query',
221 <div id="cfg-Ext.form.ComboBox-minChars"></div>/**
222 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
223 * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
224 * <tt>{@link #mode} = 'local'</tt>, does not apply if
225 * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
228 <div id="cfg-Ext.form.ComboBox-autoSelect"></div>/**
229 * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
230 * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
231 * unless the value of ({@link #typeAheadDelay}) were true.
234 <div id="cfg-Ext.form.ComboBox-typeAhead"></div>/**
235 * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
236 * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
240 <div id="cfg-Ext.form.ComboBox-queryDelay"></div>/**
241 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
242 * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
243 * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
246 <div id="cfg-Ext.form.ComboBox-pageSize"></div>/**
247 * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
248 * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
249 * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
250 * (defaults to <tt>0</tt>).
253 <div id="cfg-Ext.form.ComboBox-selectOnFocus"></div>/**
254 * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
255 * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
258 selectOnFocus : false,
259 <div id="cfg-Ext.form.ComboBox-queryParam"></div>/**
260 * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
261 * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
263 queryParam : 'query',
264 <div id="cfg-Ext.form.ComboBox-loadingText"></div>/**
265 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
266 * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
268 loadingText : 'Loading...',
269 <div id="cfg-Ext.form.ComboBox-resizable"></div>/**
270 * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
271 * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
272 * Defaults to <tt>false</tt>.
275 <div id="cfg-Ext.form.ComboBox-handleHeight"></div>/**
276 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
277 * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
280 <div id="cfg-Ext.form.ComboBox-allQuery"></div>/**
281 * @cfg {String} allQuery The text query to send to the server to return all records for the list
282 * with no filtering (defaults to '')
285 <div id="cfg-Ext.form.ComboBox-mode"></div>/**
286 * @cfg {String} mode Acceptable values are:
287 * <div class="mdetail-params"><ul>
288 * <li><b><tt>'remote'</tt></b> : <b>Default</b>
289 * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
290 * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
291 * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
292 * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
293 * <li><b><tt>'local'</tt></b> :
294 * <p class="sub-desc">ComboBox loads local data</p>
296 var combo = new Ext.form.ComboBox({
297 renderTo: document.body,
299 store: new Ext.data.ArrayStore({
302 'myId', // numeric value is the key
305 data: [[1, 'item1'], [2, 'item2']] // data is local
308 displayField: 'displayText',
315 <div id="cfg-Ext.form.ComboBox-minListWidth"></div>/**
316 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
317 * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
320 <div id="cfg-Ext.form.ComboBox-forceSelection"></div>/**
321 * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
322 * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
324 forceSelection : false,
325 <div id="cfg-Ext.form.ComboBox-typeAheadDelay"></div>/**
326 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
327 * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
329 typeAheadDelay : 250,
330 <div id="cfg-Ext.form.ComboBox-valueNotFoundText"></div>/**
331 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
332 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
333 * default text is used, it means there is no value set and no validation will occur on this field.
336 <div id="cfg-Ext.form.ComboBox-lazyInit"></div>/**
337 * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
338 * (defaults to <tt>true</tt>)
342 <div id="cfg-Ext.form.ComboBox-clearFilterOnReset"></div>/**
343 * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
344 * (defaults to <tt>true</tt>)
346 clearFilterOnReset : true,
348 <div id="cfg-Ext.form.ComboBox-submitValue"></div>/**
349 * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
350 * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
351 * Defaults to <tt>undefined</tt>.
353 submitValue: undefined,
355 <div id="prop-Ext.form.ComboBox-lastQuery"></div>/**
356 * The value of the match string used to filter the store. Delete this property to force a requery.
359 var combo = new Ext.form.ComboBox({
364 // delete the previous query in the beforequery event or set
365 // combo.lastQuery = null (this will reload the store the next time it expands)
366 beforequery: function(qe){
367 delete qe.combo.lastQuery;
372 * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
373 * configure the combo with <tt>lastQuery=''</tt>. Example use:
375 var combo = new Ext.form.ComboBox({
378 triggerAction: 'all',
382 * @property lastQuery
387 initComponent : function(){
388 Ext.form.ComboBox.superclass.initComponent.call(this);
390 <div id="event-Ext.form.ComboBox-expand"></div>/**
392 * Fires when the dropdown list is expanded
393 * @param {Ext.form.ComboBox} combo This combo box
396 <div id="event-Ext.form.ComboBox-collapse"></div>/**
398 * Fires when the dropdown list is collapsed
399 * @param {Ext.form.ComboBox} combo This combo box
403 <div id="event-Ext.form.ComboBox-beforeselect"></div>/**
404 * @event beforeselect
405 * Fires before a list item is selected. Return false to cancel the selection.
406 * @param {Ext.form.ComboBox} combo This combo box
407 * @param {Ext.data.Record} record The data record returned from the underlying store
408 * @param {Number} index The index of the selected item in the dropdown list
411 <div id="event-Ext.form.ComboBox-select"></div>/**
413 * Fires when a list item is selected
414 * @param {Ext.form.ComboBox} combo This combo box
415 * @param {Ext.data.Record} record The data record returned from the underlying store
416 * @param {Number} index The index of the selected item in the dropdown list
419 <div id="event-Ext.form.ComboBox-beforequery"></div>/**
421 * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
422 * cancel property to true.
423 * @param {Object} queryEvent An object that has these properties:<ul>
424 * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
425 * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
426 * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
427 * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
433 var s = Ext.getDom(this.transform);
434 if(!this.hiddenName){
435 this.hiddenName = s.name;
439 var d = [], opts = s.options;
440 for(var i = 0, len = opts.length;i < len; i++){
442 value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
443 if(o.selected && Ext.isEmpty(this.value, true)) {
446 d.push([value, o.text]);
448 this.store = new Ext.data.ArrayStore({
450 fields: ['value', 'text'],
454 this.valueField = 'value';
455 this.displayField = 'text';
457 s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
458 if(!this.lazyRender){
460 this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
461 this.render(this.el.parentNode, s);
465 //auto-configure store from local array data
467 this.store = Ext.StoreMgr.lookup(this.store);
468 if(this.store.autoCreated){
469 this.displayField = this.valueField = 'field1';
470 if(!this.store.expandData){
471 this.displayField = 'field2';
477 this.selectedIndex = -1;
478 if(this.mode == 'local'){
479 if(!Ext.isDefined(this.initialConfig.queryDelay)){
480 this.queryDelay = 10;
482 if(!Ext.isDefined(this.initialConfig.minChars)){
489 onRender : function(ct, position){
490 if(this.hiddenName && !Ext.isDefined(this.submitValue)){
491 this.submitValue = false;
493 Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
495 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
496 id: (this.hiddenId||this.hiddenName)}, 'before', true);
500 this.el.dom.setAttribute('autocomplete', 'off');
506 this.on('focus', this.initList, this, {single: true});
511 initValue : function(){
512 Ext.form.ComboBox.superclass.initValue.call(this);
513 if(this.hiddenField){
514 this.hiddenField.value =
515 Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
520 initList : function(){
522 var cls = 'x-combo-list',
523 listParent = Ext.getDom(this.getListParent() || Ext.getBody()),
524 zindex = parseInt(Ext.fly(listParent).getStyle('z-index') ,10);
526 if (this.ownerCt && !zindex){
527 this.findParentBy(function(ct){
528 zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
533 this.list = new Ext.Layer({
534 parentEl: listParent,
536 cls: [cls, this.listClass].join(' '),
538 zindex: (zindex || 12000) + 5
541 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
542 this.list.setSize(lw, 0);
543 this.list.swallowEvent('mousewheel');
544 this.assetHeight = 0;
545 if(this.syncFont !== false){
546 this.list.setStyle('font-size', this.el.getStyle('font-size'));
549 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
550 this.assetHeight += this.header.getHeight();
553 this.innerList = this.list.createChild({cls:cls+'-inner'});
554 this.mon(this.innerList, 'mouseover', this.onViewOver, this);
555 this.mon(this.innerList, 'mousemove', this.onViewMove, this);
556 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
559 this.footer = this.list.createChild({cls:cls+'-ft'});
560 this.pageTb = new Ext.PagingToolbar({
562 pageSize: this.pageSize,
565 this.assetHeight += this.footer.getHeight();
569 <div id="cfg-Ext.form.ComboBox-tpl"></div>/**
570 * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
571 * use to display each item in the dropdown list. The dropdown list is displayed in a
572 * DataView. See {@link #view}.</p>
573 * <p>The default template string is:</p><pre><code>
574 '<tpl for="."><div class="x-combo-list-item">{' + this.displayField + '}</div></tpl>'
576 * <p>Override the default value to create custom UI layouts for items in the list.
577 * For example:</p><pre><code>
578 '<tpl for="."><div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>'
580 * <p>The template <b>must</b> contain one or more substitution parameters using field
581 * names from the Combo's</b> {@link #store Store}. In the example above an
582 * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
583 * <p>To preserve the default visual look of list items, add the CSS class name
584 * <pre>x-combo-list-item</pre> to the template's container element.</p>
585 * <p>Also see {@link #itemSelector} for additional details.</p>
587 this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
588 <div id="cfg-Ext.form.ComboBox-itemSelector"></div>/**
589 * @cfg {String} itemSelector
590 * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
591 * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
592 * display will be working with.</p>
593 * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
594 * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
595 * to dropdown list items</b>
599 <div id="prop-Ext.form.ComboBox-view"></div>/**
600 * The {@link Ext.DataView DataView} used to display the ComboBox's options.
603 this.view = new Ext.DataView({
604 applyTo: this.innerList,
607 selectedClass: this.selectedClass,
608 itemSelector: this.itemSelector || '.' + cls + '-item',
609 emptyText: this.listEmptyText,
610 deferEmptyText: false
613 this.mon(this.view, {
614 containerclick : this.onViewClick,
615 click : this.onViewClick,
619 this.bindStore(this.store, true);
622 this.resizer = new Ext.Resizable(this.list, {
623 pinned:true, handles:'se'
625 this.mon(this.resizer, 'resize', function(r, w, h){
626 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
628 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
629 this.restrictHeight();
632 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
637 <div id="method-Ext.form.ComboBox-getListParent"></div>/**
638 * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
639 * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
640 * to a different Element. An example might be rendering the list inside a Menu so that clicking
641 * the list does not hide the Menu:<pre><code>
642 var store = new Ext.data.ArrayStore({
644 fields: ['initials', 'fullname'],
646 ['FF', 'Fred Flintstone'],
647 ['BR', 'Barney Rubble']
651 var combo = new Ext.form.ComboBox({
653 displayField: 'fullname',
654 emptyText: 'Select a name...',
655 forceSelection: true,
656 getListParent: function() {
657 return this.el.up('.x-menu');
659 iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
662 triggerAction: 'all',
667 var menu = new Ext.menu.Menu({
670 combo // A Field in a Menu
675 getListParent : function() {
676 return document.body;
679 <div id="method-Ext.form.ComboBox-getStore"></div>/**
680 * Returns the store associated with this combo.
681 * @return {Ext.data.Store} The store
683 getStore : function(){
688 bindStore : function(store, initial){
689 if(this.store && !initial){
690 if(this.store !== store && this.store.autoDestroy){
691 this.store.destroy();
693 this.store.un('beforeload', this.onBeforeLoad, this);
694 this.store.un('load', this.onLoad, this);
695 this.store.un('exception', this.collapse, this);
700 this.view.bindStore(null);
703 this.pageTb.bindStore(null);
709 this.lastQuery = null;
711 this.pageTb.bindStore(store);
715 this.store = Ext.StoreMgr.lookup(store);
718 beforeload: this.onBeforeLoad,
720 exception: this.collapse
724 this.view.bindStore(store);
730 Ext.form.ComboBox.superclass.reset.call(this);
731 if(this.clearFilterOnReset && this.mode == 'local'){
732 this.store.clearFilter();
737 initEvents : function(){
738 Ext.form.ComboBox.superclass.initEvents.call(this);
741 this.keyNav = new Ext.KeyNav(this.el, {
743 this.inKeyMode = true;
747 "down" : function(e){
748 if(!this.isExpanded()){
749 this.onTriggerClick();
751 this.inKeyMode = true;
756 "enter" : function(e){
771 doRelay : function(e, h, hname){
772 if(hname == 'down' || this.scope.isExpanded()){
773 // this MUST be called before ComboBox#fireKey()
774 var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
775 if(!Ext.isIE && Ext.EventManager.useKeydown){
776 // call Combo#fireKey() for browsers which use keydown event (except IE)
777 this.scope.fireKey(e);
785 defaultEventAction: 'stopEvent'
787 this.queryDelay = Math.max(this.queryDelay || 10,
788 this.mode == 'local' ? 10 : 250);
789 this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
791 this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
793 if(!this.enableKeyEvents){
794 this.mon(this.el, 'keyup', this.onKeyUp, this);
800 onDestroy : function(){
802 this.dqTask.cancel();
805 this.bindStore(null);
812 Ext.destroyMembers(this, 'hiddenField');
813 Ext.form.ComboBox.superclass.onDestroy.call(this);
817 fireKey : function(e){
818 if (!this.isExpanded()) {
819 Ext.form.ComboBox.superclass.fireKey.call(this, e);
824 onResize : function(w, h){
825 Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
826 if(this.isVisible() && this.list){
833 doResize: function(w){
834 if(!Ext.isDefined(this.listWidth)){
835 var lw = Math.max(w, this.minListWidth);
836 this.list.setWidth(lw);
837 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
842 onEnable : function(){
843 Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
844 if(this.hiddenField){
845 this.hiddenField.disabled = false;
850 onDisable : function(){
851 Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
852 if(this.hiddenField){
853 this.hiddenField.disabled = true;
858 onBeforeLoad : function(){
862 this.innerList.update(this.loadingText ?
863 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
864 this.restrictHeight();
865 this.selectedIndex = -1;
873 if(this.store.getCount() > 0 || this.listEmptyText){
875 this.restrictHeight();
876 if(this.lastQuery == this.allQuery){
878 this.el.dom.select();
881 if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
882 this.select(0, true);
885 if(this.autoSelect !== false){
888 if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
889 this.taTask.delay(this.typeAheadDelay);
899 onTypeAhead : function(){
900 if(this.store.getCount() > 0){
901 var r = this.store.getAt(0);
902 var newValue = r.data[this.displayField];
903 var len = newValue.length;
904 var selStart = this.getRawValue().length;
906 this.setRawValue(newValue);
907 this.selectText(selStart, newValue.length);
913 assertValue : function(){
915 var val = this.getRawValue(),
916 rec = this.findRecord(this.displayField, val);
918 if(!rec && this.forceSelection){
919 if(val.length > 0 && val != this.emptyText){
920 this.el.dom.value = Ext.value(this.lastSelectionText, '');
921 this.applyEmptyText();
927 val = rec.get(this.valueField || this.displayField);
935 onSelect : function(record, index){
936 if(this.fireEvent('beforeselect', this, record, index) !== false){
937 this.setValue(record.data[this.valueField || this.displayField]);
939 this.fireEvent('select', this, record, index);
945 var hf = this.hiddenField;
946 return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
949 <div id="method-Ext.form.ComboBox-getValue"></div>/**
950 * Returns the currently selected field value or empty string if no value is set.
951 * @return {String} value The selected value
953 getValue : function(){
955 return Ext.isDefined(this.value) ? this.value : '';
957 return Ext.form.ComboBox.superclass.getValue.call(this);
961 <div id="method-Ext.form.ComboBox-clearValue"></div>/**
962 * Clears any text/value currently set in the field
964 clearValue : function(){
965 if(this.hiddenField){
966 this.hiddenField.value = '';
968 this.setRawValue('');
969 this.lastSelectionText = '';
970 this.applyEmptyText();
974 <div id="method-Ext.form.ComboBox-setValue"></div>/**
975 * Sets the specified value into the field. If the value finds a match, the corresponding record text
976 * will be displayed in the field. If the value does not match the data value of an existing item,
977 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
978 * Otherwise the field will be blank (although the value will still be set).
979 * @param {String} value The value to match
980 * @return {Ext.form.Field} this
982 setValue : function(v){
985 var r = this.findRecord(this.valueField, v);
987 text = r.data[this.displayField];
988 }else if(Ext.isDefined(this.valueNotFoundText)){
989 text = this.valueNotFoundText;
992 this.lastSelectionText = text;
993 if(this.hiddenField){
994 this.hiddenField.value = Ext.value(v, '');
996 Ext.form.ComboBox.superclass.setValue.call(this, text);
1002 findRecord : function(prop, value){
1004 if(this.store.getCount() > 0){
1005 this.store.each(function(r){
1006 if(r.data[prop] == value){
1016 onViewMove : function(e, t){
1017 this.inKeyMode = false;
1021 onViewOver : function(e, t){
1022 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
1025 var item = this.view.findItemFromChild(t);
1027 var index = this.view.indexOf(item);
1028 this.select(index, false);
1033 onViewClick : function(doFocus){
1034 var index = this.view.getSelectedIndexes()[0],
1038 this.onSelect(r, index);
1042 if(doFocus !== false){
1049 restrictHeight : function(){
1050 this.innerList.dom.style.height = '';
1051 var inner = this.innerList.dom,
1052 pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
1053 h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
1054 ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
1055 hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
1056 space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
1058 h = Math.min(h, space, this.maxHeight);
1060 this.innerList.setHeight(h);
1061 this.list.beginUpdate();
1062 this.list.setHeight(h+pad);
1063 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1064 this.list.endUpdate();
1067 <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
1068 * Returns true if the dropdown list is expanded, else false.
1070 isExpanded : function(){
1071 return this.list && this.list.isVisible();
1074 <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
1075 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
1076 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1077 * @param {String} value The data value of the item to select
1078 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1079 * selected item if it is not currently in view (defaults to true)
1080 * @return {Boolean} True if the value matched an item in the list, else false
1082 selectByValue : function(v, scrollIntoView){
1083 if(!Ext.isEmpty(v, true)){
1084 var r = this.findRecord(this.valueField || this.displayField, v);
1086 this.select(this.store.indexOf(r), scrollIntoView);
1093 <div id="method-Ext.form.ComboBox-select"></div>/**
1094 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1095 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1096 * @param {Number} index The zero-based index of the list item to select
1097 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1098 * selected item if it is not currently in view (defaults to true)
1100 select : function(index, scrollIntoView){
1101 this.selectedIndex = index;
1102 this.view.select(index);
1103 if(scrollIntoView !== false){
1104 var el = this.view.getNode(index);
1106 this.innerList.scrollChildIntoView(el, false);
1113 selectNext : function(){
1114 var ct = this.store.getCount();
1116 if(this.selectedIndex == -1){
1118 }else if(this.selectedIndex < ct-1){
1119 this.select(this.selectedIndex+1);
1125 selectPrev : function(){
1126 var ct = this.store.getCount();
1128 if(this.selectedIndex == -1){
1130 }else if(this.selectedIndex !== 0){
1131 this.select(this.selectedIndex-1);
1137 onKeyUp : function(e){
1139 if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
1142 this.dqTask.delay(this.queryDelay);
1144 Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
1148 validateBlur : function(){
1149 return !this.list || !this.list.isVisible();
1153 initQuery : function(){
1154 this.doQuery(this.getRawValue());
1158 beforeBlur : function(){
1163 postBlur : function(){
1164 Ext.form.ComboBox.superclass.postBlur.call(this);
1166 this.inKeyMode = false;
1169 <div id="method-Ext.form.ComboBox-doQuery"></div>/**
1170 * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
1171 * query allowing the query action to be canceled if needed.
1172 * @param {String} query The SQL query to execute
1173 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1174 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
1175 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1177 doQuery : function(q, forceAll){
1178 q = Ext.isEmpty(q) ? '' : q;
1185 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1189 forceAll = qe.forceAll;
1190 if(forceAll === true || (q.length >= this.minChars)){
1191 if(this.lastQuery !== q){
1193 if(this.mode == 'local'){
1194 this.selectedIndex = -1;
1196 this.store.clearFilter();
1198 this.store.filter(this.displayField, q);
1202 this.store.baseParams[this.queryParam] = q;
1204 params: this.getParams(q)
1209 this.selectedIndex = -1;
1216 getParams : function(q){
1218 //p[this.queryParam] = q;
1221 p.limit = this.pageSize;
1226 <div id="method-Ext.form.ComboBox-collapse"></div>/**
1227 * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
1229 collapse : function(){
1230 if(!this.isExpanded()){
1234 Ext.getDoc().un('mousewheel', this.collapseIf, this);
1235 Ext.getDoc().un('mousedown', this.collapseIf, this);
1236 this.fireEvent('collapse', this);
1240 collapseIf : function(e){
1241 if(!e.within(this.wrap) && !e.within(this.list)){
1246 <div id="method-Ext.form.ComboBox-expand"></div>/**
1247 * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
1249 expand : function(){
1250 if(this.isExpanded() || !this.hasFocus){
1253 if(this.bufferSize){
1254 this.doResize(this.bufferSize);
1255 delete this.bufferSize;
1257 this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
1260 this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
1262 this.mon(Ext.getDoc(), {
1264 mousewheel: this.collapseIf,
1265 mousedown: this.collapseIf
1267 this.fireEvent('expand', this);
1270 <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
1271 * @method onTriggerClick
1275 // Implements the default empty TriggerField.onTriggerClick function
1276 onTriggerClick : function(){
1277 if(this.readOnly || this.disabled){
1280 if(this.isExpanded()){
1285 if(this.triggerAction == 'all') {
1286 this.doQuery(this.allQuery, true);
1288 this.doQuery(this.getRawValue());
1294 <div id="method-Ext.form.ComboBox-autoSize"></div>/**
1298 <div id="cfg-Ext.form.ComboBox-grow"></div>/**
1299 * @cfg {Boolean} grow @hide
1301 <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
1302 * @cfg {Number} growMin @hide
1304 <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
1305 * @cfg {Number} growMax @hide
1309 Ext.reg('combo', Ext.form.ComboBox);