1
votes

I have a bunch of panels out of which one does not have a form. While navigating between the panels I need to check if the form.isDirty(). Obviously it works fine as long as I don't hit the panel with no form on. Its a card layout and I am currently using:

Ext.getCmp('content-panel').getForm().isDirty()

I need to check before executing this line if the panel actually has a form. Is it possible to do this in ExtJS 4?

3

3 Answers

2
votes

This code is working for requirement,we can access the 'form' property of the panel.If the panel contains the form then this Property return the form object in return and if the panel doesn't contains the form it return the 'undefined' which satisfied your requirement.

var formFlag = Ext.getCmp('content-panel').form;
if(formFlag  === undefined){
   console.log('form is absent');
}else{
   console.log('form is present');//formFlag is the form object in this case
}
1
votes

The component query should help you to check if there is a form inside the panel and you have to check if the panel is a form

var panel = Ext.getCmp('content-panel');
//Check if this is a form
var isForm = panel.form
//Check if an inner panel is a form
var hasForm = panel.query('form');
if(isForm && hasForm.length > 0){
  //Is or has a form
}
0
votes

Found a workaround. Posting just in case if anyone else might be looking for same thing.

I split my statement in following

var formCmp = Ext.getCmp('content-panel'); and then called formCmp.getForm

Note: getForm and getForm() return different values.