rails action
def get_gallery_type data = [] gallery_type = GalleryType.find:all gallery_type.each do |t| data << {:gallery_type_id => t.id, :name => t.name} end render :json => {:gallery_type => data } end
store
var store = new Ext.data.JsonStore({ url: '/galleries/get_gallery_type', root: 'gallery_type', fields: ['name', 'gallery_type_id'] });
comboBox
new Ext.form.ComboBox({ store: store, name: 'gallery_type', displayField: 'name', valueField: 'gallery_type_id', fieldLabel: 'Gallery Type', typeAhead: true, forceSelection: true, triggerAction: 'all', selectOnFocus: true, readOnly: true, lazyInit: false, lazyRender: false, allowBlank: false, listeners: { 'render': function(){ store.load({ callback: function(){ if(store.getCount() == 1){ form.getForm().findField('gallery_type').setValue(store.getAt(0).get('gallery_type_id')); } } }) } } })