Combo Boxes

The js is not minified so it is readable. See combos.ml.

Data Sources

The combo box can use any type of Ext.data.Store as its data source. This means your data can be XML, JSON, arrays or any other supported format. It can be loaded using Ajax, via script tags or locally. This combo uses local data from a JS array:

// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});

// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});

// Simple ComboBox using the data store
var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
    fieldLabel: 'Select a single state',
    renderTo: 'simpleCombo',
    displayField: 'name',
    width: 500,
    labelWidth: 130,
    store: store,
    queryMode: 'local',
    typeAhead: true
});

Custom Item Templates

The combo below uses the same data, but also illustrates how to use an optional custom template to create custom UI renditions for list items by overriding the getInnerTpl method. In this case each item shows the state's abbreviation, and has a QuickTip which displays the state's nickname when hovered over.

// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});

// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});

// ComboBox with a custom item template
var customTplCombo = Ext.create('Ext.form.field.ComboBox', {
    fieldLabel: 'Select a single state',
    renderTo: 'customTplCombo',
    displayField: 'name',
    width: 500,
    labelWidth: 130,
    store: store,
    queryMode: 'local',
    listConfig: {
        getInnerTpl: function() {
            return '<div data-qtip="{name}. {slogan}">{name} ({abbr})</div>';
        }
    }
});

Multiple Selection

The combo below uses the same data once again, but allows selecting multiple values.

// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});

// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});

// ComboBox with multiple selection enabled
var multiCombo = Ext.create('Ext.form.field.ComboBox', {
    fieldLabel: 'Select multiple states',
    renderTo: 'multiSelectCombo',
    multiSelect: true,
    displayField: 'name',
    width: 500,
    labelWidth: 130,
    store: store,
    queryMode: 'local'
});

Transformation

ComboBoxes can also be created from existing HTML <select> elements on the page by specifying the transform config. This allows creation of rich ComboBox fields with autocompletion and list filtering, in an unobtrusive way.

var transformed = Ext.create('Ext.form.field.ComboBox', {
    typeAhead: true,
    transform: 'stateSelect',
    width: 135,
    forceSelection: true
});