PDA

View Full Version : Adding a listener when transforming select lists



pjturley
24 Nov 2009, 3:24 AM
Hi,

I am using the Oracle APEX tool with extjs integration and have some code that converts select lists to combo boxes. I am trying to work out how to add in functionality to copy any onchange events. I assume I need to use the listener option. This is my code

var selectfield = Ext.query('select[class!="shuttle"][class!="multiselect"]');
for (var r = 0; r < selectfield.length; r++) {
var newselect = new Ext.form.ComboBox({
id: selectfield[r].id,
typeAhead: true,
triggerAction: 'all',
transform: selectfield[r].id,
width: selectfield[r].clientWidth+5,
emptyText:'Please select...',
forceSelection: true,
maxHeight: 200,
disabled: selectfield[r].disabled
});
}

Any help or guidance would be greatly appreciated.

Many Thanks

Paul

Condor
24 Nov 2009, 4:15 AM
Is the event handler assigned using the 'onchange' attribute or by using addEventListener/attachEvent?

For the first one you could use:

var selectfield = Ext.query('select[class!="shuttle"][class!="multiselect"]');
for (var r = 0; r < selectfield.length; r++) {
var changeFn = selectfield[r].onchange;
var newselect = new Ext.form.ComboBox({
id: selectfield[r].id,
typeAhead: true,
triggerAction: 'all',
transform: selectfield[r].id,
width: selectfield[r].clientWidth + 5,
emptyText: 'Please select...',
forceSelection: true,
maxHeight: 200,
disabled: selectfield[r].disabled,
listeners: {
select: function(combo){
var d = combo.getEl().dom;
changeFn.call(d, {type: 'change', target: d, srcElement: d});
}
}
});
}

The second one is a bit harder (you would need to create and fire a change event on the original select).