PDA

View Full Version : Ext.get("myDiv").load script execution



dalsbury
9 Apr 2007, 7:28 AM
I posted this question in reply to a post response (http://extjs.com/forum/showthread.php?t=4020)

When I use the same basic structure as Joe did in his example I find that I end up with an error, though my code still accomplishes the desired results minus the error message. The error that I receive is "Ext is not defined" because the Javascript is for some reason executed twice. The first time "Ext" is not defined, and the second time "Ext" is defined.

This is the code that loads the child module:


Ext.get("mainPanel").load({
url: panelURL + panelURLParameters,
scripts: true,
text: "Loading ..."
});


If the scripts is set to false, the page still executes once, but "Ext" is still not defined. On the second pass with scripts set to true, "Ext" is defined.

The workaround that I found though it seems a kludge is the following:


<script language="JavaScript" type="text/javascript">
var myForm = function(){
var simple = new Ext.Form({
labelWidth: 75, // label settings here cascade unless overridden
url:'save-form.php'
});
simple.add(
new Ext.form.TextField({
fieldLabel: 'Email',
name: 'email',
vtype:'email',
width:175
})
);
simple.render('form-ct');
};
// This is where I prevent the error by only executing on the second pass once Ext is defined
if (typeof(window['Ext']) !== "undefined")
{
Ext.onReady(myForm);
}
</script>


This seems to stop the errors, but I am wondering if there is a way to prevent the first execution of the code.

tryanDLS
9 Apr 2007, 9:19 AM
Did you try putting your all you code in an onReady block like Joe's kid.htm example rather than just calling onReady at the end? The problem may be that it's trying access Ext before the block is done being hooked to the document.

jack.slocum
9 Apr 2007, 9:34 AM
You main page is the one that should load Ext, not sub pages. Then Ext will always be defined.

Other than that I would just be guessing and I would need to see more of how your setup is loading.

dalsbury
10 Apr 2007, 8:23 AM
My problem is solved. It was a stupid mistake. Making the transition from iframes to Joe's sample, I left my hidden iframe in my HTML, but I removed it from the BorderLayout, so it was no longer visible.

To make Joe's example work for me, I added a click handler to my menu tree, but I did not realize that the href (which I forgot to remove) in my tree would still fire pointing to the hidden iframe. The iframe would load the href first, throw an error, then the click handler would load the same page in the BorderLayout which would load without an error. Because the iframe did not load Ext libraries, the error "Ext is not defined" would occur.

Thanks for trying to help Jack, with the information I provided, nobody would have ever figured it out.

jack.slocum
10 Apr 2007, 11:50 AM
That is an odd one! Thanks for the update.