PDA

View Full Version : Firing an event in my form submit is causing a TypeError



KallDrexx
4 Jan 2011, 1:05 PM
I have the following code to build my extended formpanel


EditRequestForm = Ext.extend(Ext.form.FormPanel, {
width: 600,
bodyStyle: 'padding: 10px 10px 0 10px;',
//fileUpload: true,
isNewRequest: true, // Default to being a new request
initComponent: function () {
this.items = [{
name: 'id',
hidden: true
},
{
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name',
allowBlank: false,
anchor: '95%'
},
{
xtype: 'fileuploadfield',
fieldLabel: 'Test Plan File',
name: 'testplan',
emptyText: 'Select a Test Plan',
anchor: '95%'
},
{
xtype: 'timefield',
fieldLabel: 'Scheduled Time',
name: 'scheduledtime',
anchor: '95%'
}];

this.buttons = [{
text: 'Save',
scope: this,
handler: this.submitHandler
},
{
text: 'Cancel',
scope: this,
handler: function () { this.fireEvent(EventStrings.EditRequestCancelled); }
}];

EditRequestForm.superclass.initComponent.call(this);
},

submitHandler: function () {
if (this.getForm().isValid()) {
this.getForm().submit({
url: baseUrl + '/TestRequests/AddRequest',
waitMsg: 'Adding Request',
scope: this,
success: function (form, o) {
this.fireEvent(EventStrings.EditRequestSaved);
},

failure: function (form, o) {
Ext.Msg.show({
msg: o.result.msg || 'A server error occurred',
buttons: Ext.Msg.OK,
icon: Ext.Msg.ERROR
});
}
});
}
}
});

When the form is submitted successfully, and " this.fireEvent(EventStrings.EditRequestSaved);" is called, the following javascript error occurs on line 310 of ext-all-debug.js:


Uncaught TypeError: Cannot call method 'apply' of undefined

Using breakpoints it seems like everything is scoped correctly, as this.IsNewRecord is correctly showing as true. EventStrings.EditRequestSaved is a valid string as well.

4 Jan 2011, 1:32 PM
do you have any improperly registered event handlers? it's trying to call yourFn.apply, but since yourFn === undefined, you're getting an exception.

KallDrexx
5 Jan 2011, 6:57 AM
Aha I see now. I scoped the on() wrong and the handler I was pointing to was undefined. I didn't realize I was looking for an error with the listener rather than the fire function.

Thanks!