View Full Version : How to add empty option to combobox ?

5 Apr 2012, 7:02 AM

Is there a better way to add an empty option to a combobox than something like :

onLoad: function(store, records, successful, operation, options) {
var falseReader = Ext.create('model.reader', {id:10, login:'&nbsp'});
store.insert(0, falseReader);

It works for me but I needed to define two different stores with exactly the same values in order to be able to have one store with the empty option and one store without. So I am wondering if there is a better way.


6 Apr 2012, 7:30 AM
You can override the collectData method of the BoundList to unshift an object in the array it returns.

6 Apr 2012, 8:57 AM
Ok, thank you for your answer.
Any chance to have something like "emptyValueField" and "emptyDisplayField" in the combobox configuration in next versions ? It seems many people are looking for that, non (according to the number of workaround I found on forums) ?

Anyway, good work for these two frameworks (Extjs and sencha) and for Sencha in action



27 Apr 2012, 2:36 AM
This is what I have tried (added the green lines):

Ext.override(Ext.view.BoundList, { collectData : function(records, startIndex){
var r = [],
i = 0,
len = records.length,

for(; i < len; i++){
record = records[i];
r[r.length] = this.prepareData(record[record.persistenceProperty], startIndex + i, record);
var emptyRecord=this.pickerField.store.model.create();
r.unshift(this.prepareData(emptyRecord[emptyRecord.persistenceProperty], startIndex + i+1, emptyRecord));
return r;

But it gives an error here (red line) when opening the combo:

Ext.view.AbstractView.updateIndexes=function(startIndex, endIndex) { var ns = this.all.elements,
records = this.store.getRange(),

startIndex = startIndex || 0;
endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
for(i = startIndex; i <= endIndex; i++){
ns[i].viewIndex = i;
ns[i].viewRecordId = records[i].internalId; //error --> records[i] is undefined
if (!ns[i].boundView) {
ns[i].boundView = this.id;

25 Jun 2012, 1:47 PM
Well... this is certainly overcomplicated for something that should be a simple config on a combo, no?