You've made aAddInstanceDlg local to doAdd() - it will considered to be "new" and "undefined" everytime doAdd() is called. Here's an example of *how* to do it with a BasicDialog - it shouldn't be too hard to change yours for the LayoutDialog:
Code:
<script>
var TestDlg = function(){
var dlgLogin, frmLogin;
return {
init : function(){
},
doAdd: function(){
if (!dlgLogin)
{
dlgLogin = new Ext.BasicDialog('login-dlg', {autoCreate: true, title: 'Login', height: 160, width: 300, modal: true, closable: true, collapsible: false});
dlgLogin.addButton('Login', dlgLogin.hide, dlgLogin);
dlgLogin.addButton('Cancel', dlgLogin.hide, dlgLogin);
frmLogin = new Ext.form.Form({});
frmLogin.add(
new Ext.form.TextField({fieldLabel: 'Username', name: 'username', width: 160}),
new Ext.form.TextField({fieldLabel: 'Password', name: 'password', width: 160, inputType: 'password'})
);
frmLogin.render(dlgLogin.body);
};
dlgLogin.show();
}
};
}();
Ext.onReady(TestDlg.init, TestDlg);
</script>
</head>
<body>
<a href="javascript:TestDlg.doAdd()">test</a>
</body>
</html>