3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.form.ComboBox"></div>/**
9 * @class Ext.form.ComboBox
10 * @extends Ext.form.TriggerField
11 * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
12 * <p>A ComboBox works in a similar manner to a traditional HTML <select> field. The difference is
13 * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
14 * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
15 * which is named according to the {@link #name}.</p>
16 * <p><b><u>Events</u></b></p>
17 * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
18 var cb = new Ext.form.ComboBox({
19 // all of your config options
22 'select': yourFunction
26 // Alternatively, you can assign events after the object is created:
27 var cb = new Ext.form.ComboBox(yourOptions);
28 cb.on('select', yourFunction, yourScope);
31 * <p><b><u>ComboBox in Grid</u></b></p>
32 * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
33 * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
34 * a reusable render, for example:<pre><code>
35 // create reusable renderer
36 Ext.util.Format.comboRenderer = function(combo){
37 return function(value){
38 var record = combo.findRecord(combo.{@link #valueField}, value);
39 return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
43 // create the combo instance
44 var combo = new Ext.form.ComboBox({
45 {@link #typeAhead}: true,
46 {@link #triggerAction}: 'all',
47 {@link #lazyRender}:true,
48 {@link #mode}: 'local',
49 {@link #store}: new Ext.data.ArrayStore({
55 data: [[1, 'item1'], [2, 'item2']]
57 {@link #valueField}: 'myId',
58 {@link #displayField}: 'displayText'
61 // snippet of column model used within grid
62 var cm = new Ext.grid.ColumnModel([{
65 header: "Some Header",
66 dataIndex: 'whatever',
68 editor: combo, // specify reference to combo instance
69 renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
75 * <p><b><u>Filtering</u></b></p>
76 * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
77 * store manually see <tt>{@link #lastQuery}</tt>.</p>
79 * Create a new ComboBox.
80 * @param {Object} config Configuration options
83 Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
84 <div id="cfg-Ext.form.ComboBox-transform"></div>/**
85 * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
86 * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
87 * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
89 <div id="cfg-Ext.form.ComboBox-lazyRender"></div>/**
90 * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
91 * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
92 * defaults to <tt>false</tt>).
94 <div id="cfg-Ext.form.ComboBox-autoCreate"></div>/**
95 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
96 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
97 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
98 * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
100 <div id="cfg-Ext.form.ComboBox-store"></div>/**
101 * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
102 * Acceptable values for this property are:
103 * <div class="mdetail-params"><ul>
104 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
105 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
106 * <div class="mdetail-params"><ul>
107 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
108 * A 1-dimensional array will automatically be expanded (each array item will be the combo
109 * {@link #valueField value} and {@link #displayField text})</div></li>
110 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
111 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
112 * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
113 * </div></li></ul></div></li></ul></div>
114 * <p>See also <tt>{@link #mode}</tt>.</p>
116 <div id="cfg-Ext.form.ComboBox-title"></div>/**
117 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
118 * the dropdown list (defaults to undefined, with no header element)
122 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
123 <div id="cfg-Ext.form.ComboBox-listWidth"></div>/**
124 * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
125 * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}
127 <div id="cfg-Ext.form.ComboBox-displayField"></div>/**
128 * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
129 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'text'</tt> if
130 * {@link #transform transforming a select} a select).
131 * <p>See also <tt>{@link #valueField}</tt>.</p>
132 * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
133 * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
136 <div id="cfg-Ext.form.ComboBox-valueField"></div>/**
137 * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
138 * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'value'</tt> if
139 * {@link #transform transforming a select}).
140 * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
141 * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
143 <div id="cfg-Ext.form.ComboBox-hiddenName"></div>/**
144 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
145 * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
146 * post during a form submission. See also {@link #valueField}.
147 * <p><b>Note</b>: the hidden field's id will also default to this name if {@link #hiddenId} is not specified.
148 * The ComboBox {@link Ext.Component#id id} and the <tt>{@link #hiddenId}</tt> <b>should be different</b>, since
149 * no two DOM nodes should share the same id. So, if the ComboBox <tt>{@link Ext.form.Field#name name}</tt> and
150 * <tt>hiddenName</tt> are the same, you should specify a unique <tt>{@link #hiddenId}</tt>.</p>
152 <div id="cfg-Ext.form.ComboBox-hiddenId"></div>/**
153 * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
154 * to give the hidden field a unique id (defaults to the <tt>{@link #hiddenName}</tt>). The <tt>hiddenId</tt>
155 * and combo {@link Ext.Component#id id} should be different, since no two DOM
156 * nodes should share the same id.
158 <div id="cfg-Ext.form.ComboBox-hiddenValue"></div>/**
159 * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
160 * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
161 * <tt>{@link Ext.form.Field#value value}</tt>.
163 <div id="cfg-Ext.form.ComboBox-listClass"></div>/**
164 * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
165 * applied the dropdown list element (defaults to '').
168 <div id="cfg-Ext.form.ComboBox-selectedClass"></div>/**
169 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
170 * (defaults to <tt>'x-combo-selected'</tt>)
172 selectedClass : 'x-combo-selected',
173 <div id="cfg-Ext.form.ComboBox-listEmptyText"></div>/**
174 * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
178 <div id="cfg-Ext.form.ComboBox-triggerClass"></div>/**
179 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
180 * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
181 * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
183 triggerClass : 'x-form-arrow-trigger',
184 <div id="cfg-Ext.form.ComboBox-shadow"></div>/**
185 * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
186 * 4-way shadow, and <tt>"drop"</tt> for bottom-right
189 <div id="cfg-Ext.form.ComboBox-listAlign"></div>/**
190 * @cfg {String} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
191 * on supported anchor positions (defaults to <tt>'tl-bl?'</tt>)
193 listAlign : 'tl-bl?',
194 <div id="cfg-Ext.form.ComboBox-maxHeight"></div>/**
195 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
196 * (defaults to <tt>300</tt>)
199 <div id="cfg-Ext.form.ComboBox-minHeight"></div>/**
200 * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
201 * distance to the viewport edges (defaults to <tt>90</tt>)
204 <div id="cfg-Ext.form.ComboBox-triggerAction"></div>/**
205 * @cfg {String} triggerAction The action to execute when the trigger is clicked.
206 * <div class="mdetail-params"><ul>
207 * <li><b><tt>'query'</tt></b> : <b>Default</b>
208 * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
209 * <li><b><tt>'all'</tt></b> :
210 * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
212 * <p>See also <code>{@link #queryParam}</code>.</p>
214 triggerAction : 'query',
215 <div id="cfg-Ext.form.ComboBox-minChars"></div>/**
216 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
217 * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
218 * <tt>{@link #mode} = 'local'</tt>, does not apply if
219 * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
222 <div id="cfg-Ext.form.ComboBox-typeAhead"></div>/**
223 * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
224 * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
228 <div id="cfg-Ext.form.ComboBox-queryDelay"></div>/**
229 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
230 * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
231 * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
234 <div id="cfg-Ext.form.ComboBox-pageSize"></div>/**
235 * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
236 * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
237 * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
238 * (defaults to <tt>0</tt>).
241 <div id="cfg-Ext.form.ComboBox-selectOnFocus"></div>/**
242 * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
243 * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
246 selectOnFocus : false,
247 <div id="cfg-Ext.form.ComboBox-queryParam"></div>/**
248 * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
249 * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
251 queryParam : 'query',
252 <div id="cfg-Ext.form.ComboBox-loadingText"></div>/**
253 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
254 * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
256 loadingText : 'Loading...',
257 <div id="cfg-Ext.form.ComboBox-resizable"></div>/**
258 * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
259 * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
260 * Defaults to <tt>false</tt>.
263 <div id="cfg-Ext.form.ComboBox-handleHeight"></div>/**
264 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
265 * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
268 <div id="cfg-Ext.form.ComboBox-allQuery"></div>/**
269 * @cfg {String} allQuery The text query to send to the server to return all records for the list
270 * with no filtering (defaults to '')
273 <div id="cfg-Ext.form.ComboBox-mode"></div>/**
274 * @cfg {String} mode Acceptable values are:
275 * <div class="mdetail-params"><ul>
276 * <li><b><tt>'remote'</tt></b> : <b>Default</b>
277 * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
278 * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
279 * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
280 * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
281 * <li><b><tt>'local'</tt></b> :
282 * <p class="sub-desc">ComboBox loads local data</p>
284 var combo = new Ext.form.ComboBox({
285 renderTo: document.body,
287 store: new Ext.data.ArrayStore({
290 'myId', // numeric value is the key
293 data: [[1, 'item1'], [2, 'item2']] // data is local
296 displayField: 'displayText',
303 <div id="cfg-Ext.form.ComboBox-minListWidth"></div>/**
304 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
305 * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
308 <div id="cfg-Ext.form.ComboBox-forceSelection"></div>/**
309 * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
310 * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
312 forceSelection : false,
313 <div id="cfg-Ext.form.ComboBox-typeAheadDelay"></div>/**
314 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
315 * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
317 typeAheadDelay : 250,
318 <div id="cfg-Ext.form.ComboBox-valueNotFoundText"></div>/**
319 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
320 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
321 * default text is used, it means there is no value set and no validation will occur on this field.
324 <div id="cfg-Ext.form.ComboBox-lazyInit"></div>/**
325 * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
326 * (defaults to <tt>true</tt>)
330 <div id="prop-Ext.form.ComboBox-lastQuery"></div>/**
331 * The value of the match string used to filter the store. Delete this property to force a requery.
334 var combo = new Ext.form.ComboBox({
339 // delete the previous query in the beforequery event or set
340 // combo.lastQuery = null (this will reload the store the next time it expands)
341 beforequery: function(qe){
342 delete qe.combo.lastQuery;
347 * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
348 * configure the combo with <tt>lastQuery=''</tt>. Example use:
350 var combo = new Ext.form.ComboBox({
353 triggerAction: 'all',
357 * @property lastQuery
362 initComponent : function(){
363 Ext.form.ComboBox.superclass.initComponent.call(this);
365 <div id="event-Ext.form.ComboBox-expand"></div>/**
367 * Fires when the dropdown list is expanded
368 * @param {Ext.form.ComboBox} combo This combo box
371 <div id="event-Ext.form.ComboBox-collapse"></div>/**
373 * Fires when the dropdown list is collapsed
374 * @param {Ext.form.ComboBox} combo This combo box
377 <div id="event-Ext.form.ComboBox-beforeselect"></div>/**
378 * @event beforeselect
379 * Fires before a list item is selected. Return false to cancel the selection.
380 * @param {Ext.form.ComboBox} combo This combo box
381 * @param {Ext.data.Record} record The data record returned from the underlying store
382 * @param {Number} index The index of the selected item in the dropdown list
385 <div id="event-Ext.form.ComboBox-select"></div>/**
387 * Fires when a list item is selected
388 * @param {Ext.form.ComboBox} combo This combo box
389 * @param {Ext.data.Record} record The data record returned from the underlying store
390 * @param {Number} index The index of the selected item in the dropdown list
393 <div id="event-Ext.form.ComboBox-beforequery"></div>/**
395 * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
396 * cancel property to true.
397 * @param {Object} queryEvent An object that has these properties:<ul>
398 * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
399 * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
400 * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
401 * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
407 var s = Ext.getDom(this.transform);
408 if(!this.hiddenName){
409 this.hiddenName = s.name;
413 var d = [], opts = s.options;
414 for(var i = 0, len = opts.length;i < len; i++){
416 value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
417 if(o.selected && Ext.isEmpty(this.value, true)) {
420 d.push([value, o.text]);
422 this.store = new Ext.data.ArrayStore({
424 fields: ['value', 'text'],
428 this.valueField = 'value';
429 this.displayField = 'text';
431 s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
432 if(!this.lazyRender){
434 this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
435 this.render(this.el.parentNode, s);
436 Ext.removeNode(s); // remove it
438 Ext.removeNode(s); // remove it
441 //auto-configure store from local array data
443 this.store = Ext.StoreMgr.lookup(this.store);
444 if(this.store.autoCreated){
445 this.displayField = this.valueField = 'field1';
446 if(!this.store.expandData){
447 this.displayField = 'field2';
453 this.selectedIndex = -1;
454 if(this.mode == 'local'){
455 if(!Ext.isDefined(this.initialConfig.queryDelay)){
456 this.queryDelay = 10;
458 if(!Ext.isDefined(this.initialConfig.minChars)){
465 onRender : function(ct, position){
466 Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
468 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
469 id: (this.hiddenId||this.hiddenName)}, 'before', true);
471 // prevent input submission
472 this.el.dom.removeAttribute('name');
475 this.el.dom.setAttribute('autocomplete', 'off');
481 this.on('focus', this.initList, this, {single: true});
486 initValue : function(){
487 Ext.form.ComboBox.superclass.initValue.call(this);
488 if(this.hiddenField){
489 this.hiddenField.value =
490 Ext.isDefined(this.hiddenValue) ? this.hiddenValue :
491 Ext.isDefined(this.value) ? this.value : '';
496 initList : function(){
498 var cls = 'x-combo-list';
500 this.list = new Ext.Layer({
501 parentEl: this.getListParent(),
503 cls: [cls, this.listClass].join(' '),
507 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
508 this.list.setSize(lw, 0);
509 this.list.swallowEvent('mousewheel');
510 this.assetHeight = 0;
511 if(this.syncFont !== false){
512 this.list.setStyle('font-size', this.el.getStyle('font-size'));
515 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
516 this.assetHeight += this.header.getHeight();
519 this.innerList = this.list.createChild({cls:cls+'-inner'});
520 this.mon(this.innerList, 'mouseover', this.onViewOver, this);
521 this.mon(this.innerList, 'mousemove', this.onViewMove, this);
522 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
525 this.footer = this.list.createChild({cls:cls+'-ft'});
526 this.pageTb = new Ext.PagingToolbar({
528 pageSize: this.pageSize,
531 this.assetHeight += this.footer.getHeight();
535 <div id="cfg-Ext.form.ComboBox-tpl"></div>/**
536 * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
537 * use to display each item in the dropdown list. The dropdown list is displayed in a
538 * DataView. See {@link #view}.</p>
539 * <p>The default template string is:</p><pre><code>
540 '<tpl for="."><div class="x-combo-list-item">{' + this.displayField + '}</div></tpl>'
542 * <p>Override the default value to create custom UI layouts for items in the list.
543 * For example:</p><pre><code>
544 '<tpl for="."><div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>'
546 * <p>The template <b>must</b> contain one or more substitution parameters using field
547 * names from the Combo's</b> {@link #store Store}. In the example above an
548 * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
549 * <p>To preserve the default visual look of list items, add the CSS class name
550 * <pre>x-combo-list-item</pre> to the template's container element.</p>
551 * <p>Also see {@link #itemSelector} for additional details.</p>
553 this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
554 <div id="cfg-Ext.form.ComboBox-itemSelector"></div>/**
555 * @cfg {String} itemSelector
556 * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
557 * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
558 * display will be working with.</p>
559 * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
560 * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
561 * to dropdown list items</b>
565 <div id="prop-Ext.form.ComboBox-view"></div>/**
566 * The {@link Ext.DataView DataView} used to display the ComboBox's options.
569 this.view = new Ext.DataView({
570 applyTo: this.innerList,
573 selectedClass: this.selectedClass,
574 itemSelector: this.itemSelector || '.' + cls + '-item',
575 emptyText: this.listEmptyText
578 this.mon(this.view, 'click', this.onViewClick, this);
580 this.bindStore(this.store, true);
583 this.resizer = new Ext.Resizable(this.list, {
584 pinned:true, handles:'se'
586 this.mon(this.resizer, 'resize', function(r, w, h){
587 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
589 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
590 this.restrictHeight();
593 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
598 <div id="method-Ext.form.ComboBox-getListParent"></div>/**
599 * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
600 * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
601 * to a different Element. An example might be rendering the list inside a Menu so that clicking
602 * the list does not hide the Menu:<pre><code>
603 var store = new Ext.data.ArrayStore({
605 fields: ['initials', 'fullname'],
607 ['FF', 'Fred Flintstone'],
608 ['BR', 'Barney Rubble']
612 var combo = new Ext.form.ComboBox({
614 displayField: 'fullname',
615 emptyText: 'Select a name...',
616 forceSelection: true,
617 getListParent: function() {
618 return this.el.up('.x-menu');
620 iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
623 triggerAction: 'all',
628 var menu = new Ext.menu.Menu({
631 combo // A Field in a Menu
636 getListParent : function() {
637 return document.body;
640 <div id="method-Ext.form.ComboBox-getStore"></div>/**
641 * Returns the store associated with this combo.
642 * @return {Ext.data.Store} The store
644 getStore : function(){
649 bindStore : function(store, initial){
650 if(this.store && !initial){
651 this.store.un('beforeload', this.onBeforeLoad, this);
652 this.store.un('load', this.onLoad, this);
653 this.store.un('exception', this.collapse, this);
654 if(this.store !== store && this.store.autoDestroy){
655 this.store.destroy();
660 this.view.bindStore(null);
666 this.lastQuery = null;
668 this.pageTb.bindStore(store);
672 this.store = Ext.StoreMgr.lookup(store);
675 beforeload: this.onBeforeLoad,
677 exception: this.collapse
681 this.view.bindStore(store);
687 initEvents : function(){
688 Ext.form.ComboBox.superclass.initEvents.call(this);
690 this.keyNav = new Ext.KeyNav(this.el, {
692 this.inKeyMode = true;
696 "down" : function(e){
697 if(!this.isExpanded()){
698 this.onTriggerClick();
700 this.inKeyMode = true;
705 "enter" : function(e){
707 this.delayedCheck = true;
708 this.unsetDelayCheck.defer(10, this);
716 this.onViewClick(false);
722 doRelay : function(foo, bar, hname){
723 if(hname == 'down' || this.scope.isExpanded()){
724 return Ext.KeyNav.prototype.doRelay.apply(this, arguments);
731 this.queryDelay = Math.max(this.queryDelay || 10,
732 this.mode == 'local' ? 10 : 250);
733 this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
735 this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
737 if(this.editable !== false && !this.enableKeyEvents){
738 this.mon(this.el, 'keyup', this.onKeyUp, this);
743 onDestroy : function(){
745 this.dqTask.cancel();
748 this.bindStore(null);
755 Ext.form.ComboBox.superclass.onDestroy.call(this);
759 unsetDelayCheck : function(){
760 delete this.delayedCheck;
764 fireKey : function(e){
765 var fn = function(ev){
766 if (ev.isNavKeyPress() && !this.isExpanded() && !this.delayedCheck) {
767 this.fireEvent("specialkey", this, ev);
770 //For some reason I can't track down, the events fire in a different order in webkit.
771 //Need a slight delay here
772 if(this.inEditor && Ext.isWebKit && e.getKey() == e.TAB){
773 fn.defer(10, this, [new Ext.EventObjectImpl(e)]);
780 onResize : function(w, h){
781 Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
782 if(this.list && !Ext.isDefined(this.listWidth)){
783 var lw = Math.max(w, this.minListWidth);
784 this.list.setWidth(lw);
785 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
790 onEnable : function(){
791 Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
792 if(this.hiddenField){
793 this.hiddenField.disabled = false;
798 onDisable : function(){
799 Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
800 if(this.hiddenField){
801 this.hiddenField.disabled = true;
806 onBeforeLoad : function(){
810 this.innerList.update(this.loadingText ?
811 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
812 this.restrictHeight();
813 this.selectedIndex = -1;
821 if(this.store.getCount() > 0){
823 this.restrictHeight();
824 if(this.lastQuery == this.allQuery){
826 this.el.dom.select();
828 if(!this.selectByValue(this.value, true)){
829 this.select(0, true);
833 if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
834 this.taTask.delay(this.typeAheadDelay);
838 this.onEmptyResults();
844 onTypeAhead : function(){
845 if(this.store.getCount() > 0){
846 var r = this.store.getAt(0);
847 var newValue = r.data[this.displayField];
848 var len = newValue.length;
849 var selStart = this.getRawValue().length;
851 this.setRawValue(newValue);
852 this.selectText(selStart, newValue.length);
858 onSelect : function(record, index){
859 if(this.fireEvent('beforeselect', this, record, index) !== false){
860 this.setValue(record.data[this.valueField || this.displayField]);
862 this.fireEvent('select', this, record, index);
868 var hf = this.hiddenField;
869 return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
872 <div id="method-Ext.form.ComboBox-getValue"></div>/**
873 * Returns the currently selected field value or empty string if no value is set.
874 * @return {String} value The selected value
876 getValue : function(){
878 return Ext.isDefined(this.value) ? this.value : '';
880 return Ext.form.ComboBox.superclass.getValue.call(this);
884 <div id="method-Ext.form.ComboBox-clearValue"></div>/**
885 * Clears any text/value currently set in the field
887 clearValue : function(){
888 if(this.hiddenField){
889 this.hiddenField.value = '';
891 this.setRawValue('');
892 this.lastSelectionText = '';
893 this.applyEmptyText();
897 <div id="method-Ext.form.ComboBox-setValue"></div>/**
898 * Sets the specified value into the field. If the value finds a match, the corresponding record text
899 * will be displayed in the field. If the value does not match the data value of an existing item,
900 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
901 * Otherwise the field will be blank (although the value will still be set).
902 * @param {String} value The value to match
903 * @return {Ext.form.Field} this
905 setValue : function(v){
908 var r = this.findRecord(this.valueField, v);
910 text = r.data[this.displayField];
911 }else if(Ext.isDefined(this.valueNotFoundText)){
912 text = this.valueNotFoundText;
915 this.lastSelectionText = text;
916 if(this.hiddenField){
917 this.hiddenField.value = v;
919 Ext.form.ComboBox.superclass.setValue.call(this, text);
925 findRecord : function(prop, value){
927 if(this.store.getCount() > 0){
928 this.store.each(function(r){
929 if(r.data[prop] == value){
939 onViewMove : function(e, t){
940 this.inKeyMode = false;
944 onViewOver : function(e, t){
945 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
948 var item = this.view.findItemFromChild(t);
950 var index = this.view.indexOf(item);
951 this.select(index, false);
956 onViewClick : function(doFocus){
957 var index = this.view.getSelectedIndexes()[0];
958 var r = this.store.getAt(index);
960 this.onSelect(r, index);
962 if(doFocus !== false){
968 restrictHeight : function(){
969 this.innerList.dom.style.height = '';
970 var inner = this.innerList.dom;
971 var pad = this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight;
972 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
973 var ha = this.getPosition()[1]-Ext.getBody().getScroll().top;
974 var hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height;
975 var space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
976 h = Math.min(h, space, this.maxHeight);
978 this.innerList.setHeight(h);
979 this.list.beginUpdate();
980 this.list.setHeight(h+pad);
981 this.list.alignTo(this.wrap, this.listAlign);
982 this.list.endUpdate();
986 onEmptyResults : function(){
990 <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
991 * Returns true if the dropdown list is expanded, else false.
993 isExpanded : function(){
994 return this.list && this.list.isVisible();
997 <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
998 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
999 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1000 * @param {String} value The data value of the item to select
1001 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1002 * selected item if it is not currently in view (defaults to true)
1003 * @return {Boolean} True if the value matched an item in the list, else false
1005 selectByValue : function(v, scrollIntoView){
1006 if(!Ext.isEmpty(v, true)){
1007 var r = this.findRecord(this.valueField || this.displayField, v);
1009 this.select(this.store.indexOf(r), scrollIntoView);
1016 <div id="method-Ext.form.ComboBox-select"></div>/**
1017 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
1018 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
1019 * @param {Number} index The zero-based index of the list item to select
1020 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
1021 * selected item if it is not currently in view (defaults to true)
1023 select : function(index, scrollIntoView){
1024 this.selectedIndex = index;
1025 this.view.select(index);
1026 if(scrollIntoView !== false){
1027 var el = this.view.getNode(index);
1029 this.innerList.scrollChildIntoView(el, false);
1035 selectNext : function(){
1036 var ct = this.store.getCount();
1038 if(this.selectedIndex == -1){
1040 }else if(this.selectedIndex < ct-1){
1041 this.select(this.selectedIndex+1);
1047 selectPrev : function(){
1048 var ct = this.store.getCount();
1050 if(this.selectedIndex == -1){
1052 }else if(this.selectedIndex !== 0){
1053 this.select(this.selectedIndex-1);
1059 onKeyUp : function(e){
1061 if(this.editable !== false && (k == e.BACKSPACE || !e.isSpecialKey())){
1063 this.dqTask.delay(this.queryDelay);
1065 Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
1069 validateBlur : function(){
1070 return !this.list || !this.list.isVisible();
1074 initQuery : function(){
1075 this.doQuery(this.getRawValue());
1079 beforeBlur : function(){
1080 var val = this.getRawValue();
1081 if(this.forceSelection){
1082 if(val.length > 0 && val != this.emptyText){
1083 this.el.dom.value = Ext.isDefined(this.lastSelectionText) ? this.lastSelectionText : '';
1084 this.applyEmptyText();
1089 var rec = this.findRecord(this.displayField, val);
1091 val = rec.get(this.valueField || this.displayField);
1097 <div id="method-Ext.form.ComboBox-doQuery"></div>/**
1098 * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
1099 * query allowing the query action to be canceled if needed.
1100 * @param {String} query The SQL query to execute
1101 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1102 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
1103 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1105 doQuery : function(q, forceAll){
1106 q = Ext.isEmpty(q) ? '' : q;
1113 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
1117 forceAll = qe.forceAll;
1118 if(forceAll === true || (q.length >= this.minChars)){
1119 if(this.lastQuery !== q){
1121 if(this.mode == 'local'){
1122 this.selectedIndex = -1;
1124 this.store.clearFilter();
1126 this.store.filter(this.displayField, q);
1130 this.store.baseParams[this.queryParam] = q;
1132 params: this.getParams(q)
1137 this.selectedIndex = -1;
1144 getParams : function(q){
1146 //p[this.queryParam] = q;
1149 p.limit = this.pageSize;
1154 <div id="method-Ext.form.ComboBox-collapse"></div>/**
1155 * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
1157 collapse : function(){
1158 if(!this.isExpanded()){
1162 Ext.getDoc().un('mousewheel', this.collapseIf, this);
1163 Ext.getDoc().un('mousedown', this.collapseIf, this);
1164 this.fireEvent('collapse', this);
1168 collapseIf : function(e){
1169 if(!e.within(this.wrap) && !e.within(this.list)){
1174 <div id="method-Ext.form.ComboBox-expand"></div>/**
1175 * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
1177 expand : function(){
1178 if(this.isExpanded() || !this.hasFocus){
1181 this.list.alignTo(this.wrap, this.listAlign);
1184 this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
1188 mousewheel: this.collapseIf,
1189 mousedown: this.collapseIf
1191 this.fireEvent('expand', this);
1194 <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
1195 * @method onTriggerClick
1199 // Implements the default empty TriggerField.onTriggerClick function
1200 onTriggerClick : function(){
1204 if(this.isExpanded()){
1209 if(this.triggerAction == 'all') {
1210 this.doQuery(this.allQuery, true);
1212 this.doQuery(this.getRawValue());
1218 <div id="method-Ext.form.ComboBox-autoSize"></div>/**
1222 <div id="cfg-Ext.form.ComboBox-grow"></div>/**
1223 * @cfg {Boolean} grow @hide
1225 <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
1226 * @cfg {Number} growMin @hide
1228 <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
1229 * @cfg {Number} growMax @hide
1233 Ext.reg('combo', Ext.form.ComboBox);</pre>
\r