4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-field-ComboBox-method-constructor'><span id='Ext-form-field-ComboBox'>/**
19 </span></span> * @class Ext.form.field.ComboBox
20 * @extends Ext.form.field.Picker
22 * A combobox control with support for autocomplete, remote loading, and many other features.
24 * A ComboBox is like a combination of a traditional HTML text `<input>` field and a `<select>`
25 * field; the user is able to type freely into the field, and/or pick values from a dropdown selection
26 * list. The user can input any value by default, even if it does not appear in the selection list;
27 * to prevent free-form values and restrict them to items in the list, set {@link #forceSelection} to `true`.
29 * The selection list's options are populated from any {@link Ext.data.Store}, including remote
30 * stores. The data items in the store are mapped to each option's displayed text and backing value via
31 * the {@link #valueField} and {@link #displayField} configurations, respectively.
33 * If your store is not remote, i.e. it depends only on local data and is loaded up front, you should be
34 * sure to set the {@link #queryMode} to `'local'`, as this will improve responsiveness for the user.
36 * {@img Ext.form.ComboBox/Ext.form.ComboBox.png Ext.form.ComboBox component}
40 * // The data store containing the list of states
41 * var states = Ext.create('Ext.data.Store', {
42 * fields: ['abbr', 'name'],
44 * {"abbr":"AL", "name":"Alabama"},
45 * {"abbr":"AK", "name":"Alaska"},
46 * {"abbr":"AZ", "name":"Arizona"}
51 * // Create the combo box, attached to the states data store
52 * Ext.create('Ext.form.ComboBox', {
53 * fieldLabel: 'Choose State',
56 * displayField: 'name',
58 * renderTo: Ext.getBody()
63 * To do something when something in ComboBox is selected, configure the select event:
65 * var cb = Ext.create('Ext.form.ComboBox', {
66 * // all of your config options
69 * 'select': yourFunction
73 * // Alternatively, you can assign events after the object is created:
74 * var cb = new Ext.form.field.ComboBox(yourOptions);
75 * cb.on('select', yourFunction, yourScope);
77 * ## Multiple Selection
79 * ComboBox also allows selection of multiple items from the list; to enable multi-selection set the
80 * {@link #multiSelect} config to `true`.
83 * Create a new ComboBox.
84 * @param {Object} config Configuration options
86 * @docauthor Jason Johnston <jason@sencha.com>
88 Ext.define('Ext.form.field.ComboBox', {
89 extend:'Ext.form.field.Picker',
90 requires: ['Ext.util.DelayedTask', 'Ext.EventObject', 'Ext.view.BoundList', 'Ext.view.BoundListKeyNav', 'Ext.data.StoreManager'],
91 alternateClassName: 'Ext.form.ComboBox',
92 alias: ['widget.combobox', 'widget.combo'],
94 <span id='Ext-form-field-ComboBox-cfg-triggerCls'> /**
95 </span> * @cfg {String} triggerCls
96 * An additional CSS class used to style the trigger button. The trigger will always get the
97 * {@link #triggerBaseCls} by default and <tt>triggerCls</tt> will be <b>appended</b> if specified.
98 * Defaults to 'x-form-arrow-trigger' for ComboBox.
100 triggerCls: Ext.baseCSSPrefix + 'form-arrow-trigger',
102 <span id='Ext-form-field-ComboBox-cfg-store'> /**
103 </span> * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
104 * Acceptable values for this property are:
105 * <div class="mdetail-params"><ul>
106 * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
107 * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.Store} internally,
108 * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
109 * <div class="mdetail-params"><ul>
110 * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
111 * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
112 * {@link #valueField} and {@link #displayField})</div></li>
113 * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
114 * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
115 * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
116 * </div></li></ul></div></li></ul></div>
117 * <p>See also <tt>{@link #queryMode}</tt>.</p>
120 <span id='Ext-form-field-ComboBox-cfg-multiSelect'> /**
121 </span> * @cfg {Boolean} multiSelect
122 * If set to <tt>true</tt>, allows the combo field to hold more than one value at a time, and allows selecting
123 * multiple items from the dropdown list. The combo's text field will show all selected values separated by
124 * the {@link #delimiter}. (Defaults to <tt>false</tt>.)
128 <span id='Ext-form-field-ComboBox-cfg-delimiter'> /**
129 </span> * @cfg {String} delimiter
130 * The character(s) used to separate the {@link #displayField display values} of multiple selected items
131 * when <tt>{@link #multiSelect} = true</tt>. Defaults to <tt>', '</tt>.
135 <span id='Ext-form-field-ComboBox-cfg-displayField'> /**
136 </span> * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
137 * ComboBox (defaults to 'text').
138 * <p>See also <tt>{@link #valueField}</tt>.</p>
140 displayField: 'text',
142 <span id='Ext-form-field-ComboBox-cfg-valueField'> /**
143 </span> * @cfg {String} valueField
145 * The underlying {@link Ext.data.Field#name data value name} to bind to this ComboBox (defaults to match
146 * the value of the {@link #displayField} config).
147 * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
148 * mapped. See also <tt>{@link #displayField}</tt>.</p>
151 <span id='Ext-form-field-ComboBox-cfg-triggerAction'> /**
152 </span> * @cfg {String} triggerAction The action to execute when the trigger is clicked.
153 * <div class="mdetail-params"><ul>
154 * <li><b><tt>'all'</tt></b> : <b>Default</b>
155 * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
156 * <li><b><tt>'query'</tt></b> :
157 * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.field.Base#getRawValue raw value}.</p></li>
158 * </ul></div>
159 * <p>See also <code>{@link #queryParam}</code>.</p>
161 triggerAction: 'all',
163 <span id='Ext-form-field-ComboBox-cfg-allQuery'> /**
164 </span> * @cfg {String} allQuery The text query to send to the server to return all records for the list
165 * with no filtering (defaults to '')
169 <span id='Ext-form-field-ComboBox-cfg-queryParam'> /**
170 </span> * @cfg {String} queryParam Name of the query ({@link Ext.data.proxy.Proxy#extraParam extraParam} name for the store)
171 * as it will be passed on the querystring (defaults to <tt>'query'</tt>). If explicitly set to a falsey value it will
176 <span id='Ext-form-field-ComboBox-cfg-queryMode'> /**
177 </span> * @cfg {String} queryMode
178 * The mode for queries. Acceptable values are:
179 * <div class="mdetail-params"><ul>
180 * <li><b><tt>'remote'</tt></b> : <b>Default</b>
181 * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
182 * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
183 * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
184 * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
185 * <li><b><tt>'local'</tt></b> :
186 * <p class="sub-desc">ComboBox loads local data</p>
187 * <pre><code>
188 var combo = new Ext.form.field.ComboBox({
189 renderTo: document.body,
191 store: new Ext.data.ArrayStore({
194 'myId', // numeric value is the key
197 data: [[1, 'item1'], [2, 'item2']] // data is local
200 displayField: 'displayText',
203 * </code></pre></li>
204 * </ul></div>
210 <span id='Ext-form-field-ComboBox-cfg-pageSize'> /**
211 </span> * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.toolbar.Paging} is displayed in the
212 * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
213 * {@link Ext.toolbar.Paging#pageSize limit} parameters. Only applies when <tt>{@link #queryMode} = 'remote'</tt>
214 * (defaults to <tt>0</tt>).
218 <span id='Ext-form-field-ComboBox-cfg-queryDelay'> /**
219 </span> * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
220 * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #queryMode} = 'remote'</tt>
221 * or <tt>10</tt> if <tt>{@link #queryMode} = 'local'</tt>)
224 <span id='Ext-form-field-ComboBox-cfg-minChars'> /**
225 </span> * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
226 * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #queryMode} = 'remote'</tt> or <tt>0</tt> if
227 * <tt>{@link #queryMode} = 'local'</tt>, does not apply if <tt>{@link Ext.form.field.Trigger#editable editable} = false</tt>).
230 <span id='Ext-form-field-ComboBox-cfg-autoSelect'> /**
231 </span> * @cfg {Boolean} autoSelect <tt>true</tt> to automatically highlight the first result gathered by the data store
232 * in the dropdown list when it is opened. (Defaults to <tt>true</tt>). A false value would cause nothing in the
233 * list to be highlighted automatically, so the user would have to manually highlight an item before pressing
234 * the enter or {@link #selectOnTab tab} key to select it (unless the value of ({@link #typeAhead}) were true),
235 * or use the mouse to select a value.
239 <span id='Ext-form-field-ComboBox-cfg-typeAhead'> /**
240 </span> * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
241 * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
242 * to <tt>false</tt>)
246 <span id='Ext-form-field-ComboBox-cfg-typeAheadDelay'> /**
247 </span> * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
248 * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
252 <span id='Ext-form-field-ComboBox-cfg-selectOnTab'> /**
253 </span> * @cfg {Boolean} selectOnTab
254 * Whether the Tab key should select the currently highlighted item. Defaults to <tt>true</tt>.
258 <span id='Ext-form-field-ComboBox-cfg-forceSelection'> /**
259 </span> * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
260 * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
262 forceSelection: false,
264 <span id='Ext-form-field-ComboBox-cfg-valueNotFoundText'> /**
265 </span> * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
266 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
267 * default text is used, it means there is no value set and no validation will occur on this field.
270 <span id='Ext-form-field-ComboBox-property-lastQuery'> /**
271 </span> * The value of the match string used to filter the store. Delete this property to force a requery.
273 * <pre><code>
274 var combo = new Ext.form.field.ComboBox({
278 // delete the previous query in the beforequery event or set
279 // combo.lastQuery = null (this will reload the store the next time it expands)
280 beforequery: function(qe){
281 delete qe.combo.lastQuery;
285 * </code></pre>
286 * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
287 * configure the combo with <tt>lastQuery=''</tt>. Example use:
288 * <pre><code>
289 var combo = new Ext.form.field.ComboBox({
292 triggerAction: 'all',
295 * </code></pre>
296 * @property lastQuery
300 <span id='Ext-form-field-ComboBox-cfg-defaultListConfig'> /**
301 </span> * @cfg {Object} defaultListConfig
302 * Set of options that will be used as defaults for the user-configured {@link #listConfig} object.
306 loadingText: 'Loading...',
313 <span id='Ext-form-field-ComboBox-cfg-transform'> /**
314 </span> * @cfg {Mixed} transform
315 * The id, DOM node or {@link Ext.core.Element} of an existing HTML <tt>&lt;select&gt;</tt> element to
316 * convert into a ComboBox. The target select's options will be used to build the options in the ComboBox
317 * dropdown; a configured {@link #store} will take precedence over this.
320 <span id='Ext-form-field-ComboBox-cfg-listConfig'> /**
321 </span> * @cfg {Object} listConfig
322 * <p>An optional set of configuration properties that will be passed to the {@link Ext.view.BoundList}'s
323 * constructor. Any configuration that is valid for BoundList can be included. Some of the more useful
324 * ones are:</p>
326 * <li>{@link Ext.view.BoundList#cls} - defaults to empty</li>
327 * <li>{@link Ext.view.BoundList#emptyText} - defaults to empty string</li>
328 * <li>{@link Ext.view.BoundList#getInnerTpl} - defaults to the template defined in BoundList</li>
329 * <li>{@link Ext.view.BoundList#itemSelector} - defaults to the value defined in BoundList</li>
330 * <li>{@link Ext.view.BoundList#loadingText} - defaults to <tt>'Loading...'</tt></li>
331 * <li>{@link Ext.view.BoundList#minWidth} - defaults to <tt>70</tt></li>
332 * <li>{@link Ext.view.BoundList#maxWidth} - defaults to <tt>undefined</tt></li>
333 * <li>{@link Ext.view.BoundList#maxHeight} - defaults to <tt>300</tt></li>
334 * <li>{@link Ext.view.BoundList#resizable} - defaults to <tt>false</tt></li>
335 * <li>{@link Ext.view.BoundList#shadow} - defaults to <tt>'sides'</tt></li>
336 * <li>{@link Ext.view.BoundList#width} - defaults to <tt>undefined</tt> (automatically set to the width
337 * of the ComboBox field if {@link #matchFieldWidth} is true)</li>
344 initComponent: function() {
346 isDefined = Ext.isDefined,
348 transform = me.transform,
349 transformSelect, isLocalMode;
352 if (!store && !transform) {
353 Ext.Error.raise('Either a valid store, or a HTML select to transform, must be configured on the combo.');
355 if (me.typeAhead && me.multiSelect) {
356 Ext.Error.raise('typeAhead and multiSelect are mutually exclusive options -- please remove one of them.');
358 if (me.typeAhead && !me.editable) {
359 Ext.Error.raise('If typeAhead is enabled the combo must be editable: true -- please change one of those settings.');
361 if (me.selectOnFocus && !me.editable) {
362 Ext.Error.raise('If selectOnFocus is enabled the combo must be editable: true -- please change one of those settings.');
367 // TODO need beforeselect?
369 <span id='Ext-form-field-ComboBox-event-beforequery'> /**
370 </span> * @event beforequery
371 * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
372 * cancel property to true.
373 * @param {Object} queryEvent An object that has these properties:<ul>
374 * <li><code>combo</code> : Ext.form.field.ComboBox <div class="sub-desc">This combo box</div></li>
375 * <li><code>query</code> : String <div class="sub-desc">The query string</div></li>
376 * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
377 * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
384 * Fires when at least one list item is selected.
385 * @param {Ext.form.field.ComboBox} combo This combo box
386 * @param {Array} records The selected records
391 // Build store from 'transform' HTML select element's options
392 if (!store && transform) {
393 transformSelect = Ext.getDom(transform);
394 if (transformSelect) {
395 store = Ext.Array.map(Ext.Array.from(transformSelect.options), function(option) {
396 return [option.value, option.text];
399 me.name = transformSelect.name;
401 if (!('value' in me)) {
402 me.value = transformSelect.value;
407 me.bindStore(store, true);
409 if (store.autoCreated) {
410 me.queryMode = 'local';
411 me.valueField = me.displayField = 'field1';
412 if (!store.expanded) {
413 me.displayField = 'field2';
418 if (!isDefined(me.valueField)) {
419 me.valueField = me.displayField;
422 isLocalMode = me.queryMode === 'local';
423 if (!isDefined(me.queryDelay)) {
424 me.queryDelay = isLocalMode ? 10 : 500;
426 if (!isDefined(me.minChars)) {
427 me.minChars = isLocalMode ? 0 : 4;
430 if (!me.displayTpl) {
431 me.displayTpl = Ext.create('Ext.XTemplate',
432 '<tpl for=".">' +
433 '{[typeof values === "string" ? values : values.' + me.displayField + ']}' +
434 '<tpl if="xindex < xcount">' + me.delimiter + '</tpl>' +
437 } else if (Ext.isString(me.displayTpl)) {
438 me.displayTpl = Ext.create('Ext.XTemplate', me.displayTpl);
443 me.doQueryTask = Ext.create('Ext.util.DelayedTask', me.doRawQuery, me);
445 // store has already been loaded, setValue
446 if (me.store.getCount() > 0) {
447 me.setValue(me.value);
450 // render in place of 'transform' select
451 if (transformSelect) {
452 me.render(transformSelect.parentNode, transformSelect);
453 Ext.removeNode(transformSelect);
458 beforeBlur: function() {
460 me.doQueryTask.cancel();
461 if (me.forceSelection) {
469 assertValue: function() {
471 value = me.getRawValue(),
474 if (me.multiSelect) {
475 // For multiselect, check that the current displayed value matches the current
476 // selection, if it does not then revert to the most recent selection.
477 if (value !== me.getDisplayValue()) {
478 me.setValue(me.lastSelection);
481 // For single-select, match the displayed value to a record and select it,
482 // if it does not match a record then revert to the most recent selection.
483 rec = me.findRecordByDisplay(value);
487 me.setValue(me.lastSelection);
493 onTypeAhead: function() {
495 displayField = me.displayField,
496 record = me.store.findRecord(displayField, me.getRawValue()),
497 boundList = me.getPicker(),
498 newValue, len, selStart;
501 newValue = record.get(displayField);
502 len = newValue.length;
503 selStart = me.getRawValue().length;
505 boundList.highlightItem(boundList.getNode(record));
507 if (selStart !== 0 && selStart !== len) {
508 me.setRawValue(newValue);
509 me.selectText(selStart, newValue.length);
514 // invoked when a different store is bound to this combo
516 resetToDefault: function() {
520 bindStore: function(store, initial) {
524 // this code directly accesses this.picker, bc invoking getPicker
525 // would create it when we may be preping to destroy it
526 if (oldStore && !initial) {
527 if (oldStore !== store && oldStore.autoDestroy) {
533 exception: me.collapse
539 me.picker.bindStore(null);
548 me.store = Ext.data.StoreManager.lookup(store);
552 exception: me.collapse
556 me.picker.bindStore(store);
566 if (me.picker && !me.picker.getSelectionModel().hasSelection()) {
571 <span id='Ext-form-field-ComboBox-method-doRawQuery'> /**
573 * Execute the query with the raw contents within the textfield.
575 doRawQuery: function() {
576 this.doQuery(this.getRawValue());
579 <span id='Ext-form-field-ComboBox-method-doQuery'> /**
580 </span> * Executes a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
581 * query allowing the query action to be canceled if needed.
582 * @param {String} queryString The SQL query to execute
583 * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
584 * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
585 * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
586 * @return {Boolean} true if the query was permitted to run, false if it was cancelled by a {@link #beforequery} handler.
588 doQuery: function(queryString, forceAll) {
589 queryString = queryString || '';
591 // store in object and pass by reference in 'beforequery'
592 // so that client code can modify values.
601 isLocalMode = me.queryMode === 'local';
603 if (me.fireEvent('beforequery', qe) === false || qe.cancel) {
607 // get back out possibly modified values
608 queryString = qe.query;
609 forceAll = qe.forceAll;
611 // query permitted to run
612 if (forceAll || (queryString.length >= me.minChars)) {
613 // expand before starting query so LoadMask can position itself correctly
616 // make sure they aren't querying the same thing
617 if (!me.queryCaching || me.lastQuery !== queryString) {
618 me.lastQuery = queryString;
619 store.clearFilter(!forceAll);
622 store.filter(me.displayField, queryString);
626 params: me.getParams(queryString)
631 // Clear current selection if it does not match the current value in the field
632 if (me.getRawValue() !== me.getDisplayValue()) {
633 me.ignoreSelection++;
634 me.picker.getSelectionModel().deselectAll();
635 me.ignoreSelection--;
649 getParams: function(queryString) {
651 pageSize = this.pageSize,
652 param = this.queryParam;
655 p[param] = queryString;
665 <span id='Ext-form-field-ComboBox-method-doAutoSelect'> /**
667 * If the autoSelect config is true, and the picker is open, highlights the first item.
669 doAutoSelect: function() {
672 lastSelected, itemNode;
673 if (picker && me.autoSelect && me.store.getCount() > 0) {
674 // Highlight the last selected item and scroll it into view
675 lastSelected = picker.getSelectionModel().lastSelected;
676 itemNode = picker.getNode(lastSelected || 0);
678 picker.highlightItem(itemNode);
679 picker.listEl.scrollChildIntoView(itemNode, false);
684 doTypeAhead: function() {
685 if (!this.typeAheadTask) {
686 this.typeAheadTask = Ext.create('Ext.util.DelayedTask', this.onTypeAhead, this);
688 if (this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE) {
689 this.typeAheadTask.delay(this.typeAheadDelay);
693 onTriggerClick: function() {
695 if (!me.readOnly && !me.disabled) {
700 if (me.triggerAction === 'all') {
701 me.doQuery(me.allQuery, true);
703 me.doQuery(me.getRawValue());
711 // store the last key and doQuery if relevant
712 onKeyUp: function(e, t) {
716 if (!me.readOnly && !me.disabled && me.editable) {
718 // we put this in a task so that we can cancel it if a user is
719 // in and out before the queryDelay elapses
721 // perform query w/ any normal key or backspace or delete
722 if (!e.isSpecialKey() || key == e.BACKSPACE || key == e.DELETE) {
723 me.doQueryTask.delay(me.queryDelay);
727 if (me.enableKeyEvents) {
728 me.callParent(arguments);
732 initEvents: function() {
737 * Setup keyboard handling. If enableKeyEvents is true, we already have
738 * a listener on the inputEl for keyup, so don't create a second.
740 if (!me.enableKeyEvents) {
741 me.mon(me.inputEl, 'keyup', me.onKeyUp, me);
745 createPicker: function() {
748 menuCls = Ext.baseCSSPrefix + 'menu',
751 mode: me.multiSelect ? 'SIMPLE' : 'SINGLE'
756 cls: me.el.up('.' + menuCls) ? menuCls : '',
758 displayField: me.displayField,
759 focusOnToFront: false,
760 pageSize: me.pageSize
761 }, me.listConfig, me.defaultListConfig);
763 picker = me.picker = Ext.create('Ext.view.BoundList', opts);
766 itemclick: me.onItemClick,
767 refresh: me.onListRefresh,
771 me.mon(picker.getSelectionModel(), {
772 selectionChange: me.onListSelectionChange,
779 onListRefresh: function() {
781 this.syncSelection();
784 onItemClick: function(picker, record){
786 * If we're doing single selection, the selection change events won't fire when
787 * clicking on the selected element. Detect it here.
790 lastSelection = me.lastSelection,
791 valueField = me.valueField,
794 if (!me.multiSelect && lastSelection) {
795 selected = lastSelection[0];
796 if (record.get(valueField) === selected.get(valueField)) {
802 onListSelectionChange: function(list, selectedRecords) {
804 // Only react to selection if it is not called from setValue, and if our list is
805 // expanded (ignores changes to the selection model triggered elsewhere)
806 if (!me.ignoreSelection && me.isExpanded) {
807 if (!me.multiSelect) {
808 Ext.defer(me.collapse, 1, me);
810 me.setValue(selectedRecords, false);
811 if (selectedRecords.length > 0) {
812 me.fireEvent('select', me, selectedRecords);
818 <span id='Ext-form-field-ComboBox-method-onExpand'> /**
820 * Enables the key nav for the BoundList when it is expanded.
822 onExpand: function() {
824 keyNav = me.listKeyNav,
825 selectOnTab = me.selectOnTab,
826 picker = me.getPicker();
828 // Handle BoundList navigation from the input field. Insert a tab listener specially to enable selectOnTab.
832 keyNav = me.listKeyNav = Ext.create('Ext.view.BoundListKeyNav', this.inputEl, {
837 this.selectHighlighted(e);
840 // Tab key event is allowed to propagate to field
846 // While list is expanded, stop tab monitoring from Ext.form.field.Trigger so it doesn't short-circuit selectOnTab
848 me.ignoreMonitorTab = true;
851 Ext.defer(keyNav.enable, 1, keyNav); //wait a bit so it doesn't react to the down arrow opening the picker
855 <span id='Ext-form-field-ComboBox-method-onCollapse'> /**
857 * Disables the key nav for the BoundList when it is collapsed.
859 onCollapse: function() {
861 keyNav = me.listKeyNav;
864 me.ignoreMonitorTab = false;
868 <span id='Ext-form-field-ComboBox-method-select'> /**
869 </span> * Selects an item by a {@link Ext.data.Model Model}, or by a key value.
872 select: function(r) {
873 this.setValue(r, true);
876 <span id='Ext-form-field-ComboBox-method-findRecord'> /**
877 </span> * Find the record by searching for a specific field/value combination
878 * Returns an Ext.data.Record or false
881 findRecord: function(field, value) {
883 idx = ds.findExact(field, value);
884 return idx !== -1 ? ds.getAt(idx) : false;
886 findRecordByValue: function(value) {
887 return this.findRecord(this.valueField, value);
889 findRecordByDisplay: function(value) {
890 return this.findRecord(this.displayField, value);
893 <span id='Ext-form-field-ComboBox-method-setValue'> /**
894 </span> * Sets the specified value(s) into the field. For each value, if a record is found in the {@link #store} that
895 * matches based on the {@link #valueField}, then that record's {@link #displayField} will be displayed in the
896 * field. If no match is found, and the {@link #valueNotFoundText} config option is defined, then that will be
897 * displayed as the default field text. Otherwise a blank value will be shown, although the value will still be set.
898 * @param {String|Array} value The value(s) to be set. Can be either a single String or {@link Ext.data.Model},
899 * or an Array of Strings or Models.
900 * @return {Ext.form.field.Field} this
902 setValue: function(value, doSelect) {
904 valueNotFoundText = me.valueNotFoundText,
905 inputEl = me.inputEl,
911 if (me.store.loading) {
912 // Called while the Store is loading. Ensure it is processed by the onLoad method.
917 // This method processes multi-values, so ensure value is an array.
918 value = Ext.Array.from(value);
920 // Loop through values
921 for (i = 0, len = value.length; i < len; i++) {
923 if (!record || !record.isModel) {
924 record = me.findRecordByValue(record);
926 // record found, select it.
929 displayTplData.push(record.data);
930 processedValue.push(record.get(me.valueField));
932 // record was not found, this could happen because
933 // store is not loaded or they set a value not in the store
935 // if valueNotFoundText is defined, display it, otherwise display nothing for this value
936 if (Ext.isDefined(valueNotFoundText)) {
937 displayTplData.push(valueNotFoundText);
939 processedValue.push(value[i]);
943 // Set the value of this field. If we are multiselecting, then that is an array.
944 me.value = me.multiSelect ? processedValue : processedValue[0];
945 if (!Ext.isDefined(me.value)) {
948 me.displayTplData = displayTplData; //store for getDisplayValue method
949 me.lastSelection = me.valueModels = models;
951 if (inputEl && me.emptyText && !Ext.isEmpty(value)) {
952 inputEl.removeCls(me.emptyCls);
955 // Calculate raw value from the collection of Model data
956 me.setRawValue(me.getDisplayValue());
959 if (doSelect !== false) {
967 <span id='Ext-form-field-ComboBox-method-getDisplayValue'> /**
968 </span> * @private Generate the string value to be displayed in the text field for the currently stored value
970 getDisplayValue: function() {
971 return this.displayTpl.apply(this.displayTplData);
974 getValue: function() {
975 // If the user has not changed the raw field value since a value was selected from the list,
976 // then return the structured value from the selection. If the raw field value is different
977 // than what would be displayed due to selection, return that raw value.
980 rawValue = me.getRawValue(), //current value of text field
981 value = me.value; //stored value from last selection or setValue() call
983 if (me.getDisplayValue() !== rawValue) {
985 me.value = me.displayTplData = me.valueModels = null;
987 me.ignoreSelection++;
988 picker.getSelectionModel().deselectAll();
989 me.ignoreSelection--;
996 getSubmitValue: function() {
997 return this.getValue();
1000 isEqual: function(v1, v2) {
1001 var fromArray = Ext.Array.from,
1008 if (len !== v2.length) {
1012 for(i = 0; i < len; i++) {
1013 if (v2[i] !== v1[i]) {
1021 <span id='Ext-form-field-ComboBox-method-clearValue'> /**
1022 </span> * Clears any value currently set in the ComboBox.
1024 clearValue: function() {
1028 <span id='Ext-form-field-ComboBox-method-syncSelection'> /**
1029 </span> * @private Synchronizes the selection in the picker to match the current value of the combobox.
1031 syncSelection: function() {
1033 ExtArray = Ext.Array,
1035 selection, selModel;
1037 // From the value, find the Models that are in the store's current data
1039 ExtArray.forEach(me.valueModels || [], function(value) {
1040 if (value && value.isModel && me.store.indexOf(value) >= 0) {
1041 selection.push(value);
1045 // Update the selection to match
1046 me.ignoreSelection++;
1047 selModel = picker.getSelectionModel();
1048 selModel.deselectAll();
1049 if (selection.length) {
1050 selModel.select(selection);
1052 me.ignoreSelection--;