PDA

View Full Version : Add new public event while extend on fields



mdombos
29 Jul 2007, 8:58 AM
first of all sorry for my English :(

Is there any way to add a public event to the object while it is being extended?

So after i create the the new form object i want to add en eventlistener to them with the new event.



var formobject new Ext.form.NewField({
name: "Field Name"
});
formobject.on('NewEvent',function(){});


So how can i do it?

tryanDLS
29 Jul 2007, 5:12 PM
Any class that is descended from Observable can add events http://extjs.com/deploy/ext-1.1-rc1/docs/output/Ext.util.Observable.html#addEvents

mdombos
30 Jul 2007, 9:38 AM
I tried it alredy.

Here is my code which i wrote.



Ext.form.NewField = function(config){
Ext.form.NewField.superclass.constructor.call(this, config);
.
.
.
this.addEvents({
modifyRequest : true
});
};
Ext.extend(Ext.form.NewField, Ext.form.Field, {
// private

onRender : function(ct, position){
...
this.modifyRequest();
...
},
modifyRequest : function(){
this.fireEvent("modifyRequest", this);
alert('modifyRequest fired!');
}
});
Ext.onReady(function(){
frm = new Ext.form.Form({
labelAlign: 'top'
});

frm.add( new Ext.form.NewField({
name: "testfield"
})
);
frm.findField('testfield').on('modifyRequest',function () { alert('It works!')});
frm.render('divForm');
});


so when i perform the action which calls the modifyRequest function the "modifyRequest fired!" window pops up, but the "It works!" does not. Why?

tryanDLS
30 Jul 2007, 10:07 AM
Try making your event name lowercase.

mdombos
30 Jul 2007, 10:20 AM
Try making your event name lowercase.

I changed it, but it did not help!