PDA

View Full Version : Cannot call method 'getForm' of undefined - Problems with Ext.getCmp().getForm



ggleny
14 Mar 2013, 7:19 AM
hi, i have problems with getForm, my code is nexti have a InsertEdit function, which receives an object, for example

constructor {id: "TEstB", text: "Accept", tooltip: "Accept", iconCls: "acceptForm", gridId: "include/render.php?viewName=test/deviceListar&history=defaultů}
componentCls: "x-btn"


componentLayout: constructor
disabled: false
events: Object
formId: "include/render.php?viewName=test/device&fromPage=deviceListForm"
gridId: "include/render.php?viewName=test/deviceListar&history=default
hasListeners: HasListeners
iconCls: "acceptForm"
id: "TEstB"
initialConfig: Object
loader: null
mons: Array[0]
plugins: undefined
protoEl: constructor
renderData: Object
renderSelectors: Object
stateEvents: Array[0]
stateId: undefined
text: "Accept"
tooltip: "Accept"
proto__: TemplateClass




and the function is as follows, with the error that is generated in the same.

function insertEdit(btn) {
var form = Ext.getCmp(btn.formId).getForm();
!Uncaught TypeError: Cannot call method 'getForm' of undefined
var grid = Ext.getCmp(btn.gridId);
var validate;
validate=validateMe(form);

if (validate == 0)
{
form.submit({
waitMsg : 'Please Wait...',
method: 'post',
success: function(result, request) {
var req = Ext.JSON.decode(request.response.responseText);


if (!Ext.isEmpty(req.reloadFields))
{
for (var i = 0 ; i < form.items.length; i++)
{
for (var j = 0 ; j< req.reloadFields.length; j++)
{
if (form.items.items[i].name == req.reloadFields[j].name)
form.items.items[i].setValue(req.reloadFields[j].value);
}
}
}
Ext.Msg.alert('Success',"Operation was successful");
if( ! Ext.isEmpty(grid) ) grid.store.reload();
},
failure: function(result,request) {
if(Ext.isDefined(request.response))
{
var req = Ext.JSON.decode(request.response.responseText);
}
if(!Ext.isDefined(request.response))
{
Ext.MessageBox.alert("Error","Failed Operation");
}else{
Ext.MessageBox.alert("Error",req.desc);//, Error Description: "+ result.responseText);
}
}
});
}else{
Ext.Msg.alert("Error",validate);
}
}



this function is call for
var btn = new Ext.Button({
id:"TEstB",
text: 'Accept',
tooltip: 'Accept',
iconCls: 'acceptForm',
gridId: this.gridId,
formId: this.formId,
disabled: moduleData.type == 'view' ? true : false
});
//btn.on('click', insertEdit.createDelegate(btn)); // change to the next line.
btn.on('click', Ext.bind(insertEdit(btn)));

thanks for the help

mitchellsimoens
17 Mar 2013, 7:48 AM
So the getCmp is returning undefined. This line:


btn.on('click', Ext.bind(insertEdit(btn)));

will execute insertEdit right away not when click is fired on the button.

ggleny
28 Jun 2013, 12:50 PM
thank you very much the problem is solved.