PDA

View Full Version : Show Dialogs automaticly



kladdkaka
3 May 2007, 7:34 AM
Hi!

I want a dialog to pop up the moment the page loads like body onload or by showing it with a function.

I looked at the examples and I can get the dialogs to show by clicking buttons. I'm now wondering what changes I need to make in order to show the dialog directly. I used this example:


/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/

// create the HelloWorld application (single instance)
var HelloWorld = function(){
// everything in this space is private and only accessible in the HelloWorld block

// define some private variables
var dialog, showBtn;

// return a public interface
return {
init : function(){
showBtn = Ext.get('show-dialog-btn');
// attach to click event
showBtn.on('click', this.showDialog, this);
},

showDialog : function(){
if(!dialog){ // lazy initialize the dialog and only create it once
dialog = new Ext.BasicDialog("hello-dlg", {
autoTabs:true,
width:500,
height:300,
shadow:true,
minWidth:300,
minHeight:250,
proxyDrag: true
});
dialog.addKeyListener(27, dialog.hide, dialog);
dialog.addButton('Submit', dialog.hide, dialog).disable();
dialog.addButton('Close', dialog.hide, dialog);
}
dialog.show(showBtn.dom);
}
};
}();

// using onDocumentReady instead of window.onload initializes the application
// when the DOM is ready, without waiting for images and other resources to load
Ext.onReady(HelloWorld.init, HelloWorld, true);

tryanDLS
3 May 2007, 9:16 AM
I don't want to sound harsh, but your question implies a lack of programming skill. If you can not look at the piece of code and understand enough to determine how to get the dialog to appear without a button click, you're going to get frustrated very quickly. I don't want to scare you off, but using the Ext framework requires more than a cut-and-paste knowledge of development. People here are willing to help out and answer questions, but this isn't a Programming 101 forum.

The answer is to change the last line to

Ext.onReady(HelloWorld.showDialog, HelloWorld, true);
and call
dialog.show() instead of dialog.show(showBtn.dom)