PDA

View Full Version : Extend ComboBox with default "Other..." option



strictlyphp
16 Nov 2010, 8:58 AM
Hi All,

I want to extend the Ext.form.ComboBox with a default "Other..." item (preferrably last in the list of items) and bind an event to this item when selected.
The ComboBox is filled with data from an Ext.data.JsonStore.
What is the best way to approach this (if possible)?

Thanks a lot!
Sam

strictlyphp
18 Nov 2010, 4:24 AM
Should I look into adding an item to the JsonStore or is it better to add an aditional item when rendering the element?

strictlyphp
19 Nov 2010, 4:07 AM
In case someone can use this, I managed to do this with:



Ext.onReady(function() {
ux.OtherComboBox = Ext.extend(Ext.form.ComboBox, {
otherText: 'Other...',
initComponent: function()
{
var otherRecord = new this.store.recordType({
name: this.otherText
});
this.store.addListener('load', function() {
this.insert(this.getCount(), otherRecord);
});
ux.OtherComboBox.superclass.initComponent.call(this, arguments);
this.addListener('select', function(combo, record, index) {
if (otherRecord === record) {
combo.fireEvent('selectOther');
}
});
}
});
Ext.reg('othercombo', ux.OtherComboBox);
});