PDA

View Full Version : findParentByType() is null or not an object



DougMcDonald
8 Feb 2012, 12:34 AM
Hi all,

I have a slightly odd situation whereby I was intended to use the findParentByType function to find the parent window of a button (specifically a cancel button to hide it).

In the handler of the button I simply had 'this.findParentByType('window').hide();' but for some reason I'm getting back 'this.findParentById() is null or not an object'

Looking at 'this' it does appear to be the component instance of the cancel button, so I wonder what I'm missing here? Is my function usage incorrect?

The docs seem to suggest the function should be available on Ext.Component, so is there anything else I'd need to do to implement this functionality?

Many thanks,

Doug

mitchellsimoens
8 Feb 2012, 7:12 AM
This works for me:


new Ext.Window({
width : 400,
height : 400,
title : 'Test',
buttons : [
{
text : 'Test',
handler : function(btn) {
var win = btn.findParentByType('window');

console.log(win);
}
}
]
}).show();

DougMcDonald
8 Feb 2012, 9:21 AM
Thanks for the reply Mitchell,

I've since realised that my button was in fact stuck in an iFrame, so as a result I think it's having trouble finding a parent outside of it's iFrame.
(in that, the call to findParentByType() is returning null for the particular xtype)

I don't suppose there is a method to 'hop' out of the iFrame easily? I can't reference my window directly (easily) as it's ID is generated dynamically I'm afraid :(

mitchellsimoens
8 Feb 2012, 9:24 AM
I would make the scope of the handler that of the window then.

DougMcDonald
9 Feb 2012, 12:09 AM
Excuse my ignorance here, not too hot on the scope change side of things, how would I go about switch the scope?
Do you mean set the button handler up on the parent iFrame to respond to child buttons? rather than try to do it from the child button and close the parent window?