RouslanZenetl
27 Jan 2009, 11:17 AM
Here's my take on a simple multi-select combobox. Tested with Ext 2.2:
Ext.form.MultiComboBox = Ext.extend(Ext.form.ComboBox, {
sep: ', ',
onSelect: function(record, index) {
if (this.fireEvent('beforeselect', this, record, index) !== false) {
var values = this.getValue().split(this.sep);
var selected_value = record.data[this.valueField || this.displayField];
if (selected_value === this.emptyText) values = [this.emptyText];
var i = values.indexOf(selected_value);
if (i<0) {
if (values.length<1||values[0]==='') {
values[0] = selected_value;
} else {
values.push(selected_value)
}
} else {
values.splice(i,1);
}
this.setValue(values.sort().join(this.sep))
this.fireEvent('select', this, record, index);
}
}
});
Ext.reg('multicombo', Ext.form.MultiComboBox);
Ext.form.MultiComboBox = Ext.extend(Ext.form.ComboBox, {
sep: ', ',
onSelect: function(record, index) {
if (this.fireEvent('beforeselect', this, record, index) !== false) {
var values = this.getValue().split(this.sep);
var selected_value = record.data[this.valueField || this.displayField];
if (selected_value === this.emptyText) values = [this.emptyText];
var i = values.indexOf(selected_value);
if (i<0) {
if (values.length<1||values[0]==='') {
values[0] = selected_value;
} else {
values.push(selected_value)
}
} else {
values.splice(i,1);
}
this.setValue(values.sort().join(this.sep))
this.fireEvent('select', this, record, index);
}
}
});
Ext.reg('multicombo', Ext.form.MultiComboBox);