PDA

View Full Version : How to get the button-object from a window



humpdi
22 Dec 2009, 4:05 PM
hello!

what i want to do is simple, and i think somebody got that problem before, but i didnt have found that specific problem in forum.

oke, the thing is that i want to build window (works) with two tabs (works) which contains 2 different forms (works). now i want to change the buttons of the window, dependable on which tab the user chose. therefor i want to hide the submit-button for the first form and show another, when clicking on the second tab. here is my code

html:

<div id="login-win" class="login-win x-hidden">
<div class="x-window-header"><?php lang("welcome"); ?></div>
<div id="login-tabs">
<div id="tab1" class="x-tab" title="<?php lang("login"); ?>"></div>
<div id="tab2" class="x-tab" title="<?php lang("register"); ?>"></div>
</div>
</div>
js:


Ext.onReady(function(){

Ext.QuickTips.init();

var login = new Ext.FormPanel({
applyTo: 'tab1',
labelWidth:100,
url:'sites/login/login.php',
bodyStyle: 'padding:15px; border:0px;',
defaultType:'textfield',
monitorValid:true,
items:[{
fieldLabel:'Benutzername',
name:'loginUsername',
allowBlank:false
},{
fieldLabel:'Passwort',
name:'loginPassword',
inputType:'password',
allowBlank:false
}]
});

var register = new Ext.FormPanel({
applyTo: 'tab2',
labelWidth:100,
url:'sites/login/register.php',
bodyStyle: 'padding:15px; border:0px;',
defaultType:'textfield',
monitorValid:true,
items:[{ }]
});

var win = new Ext.Window({
applyTo:'login-win',
layout:'fit',
width:350,
height:200,
closable:false,
plain: true,
items: new Ext.TabPanel({
applyTo: 'login-tabs',
autoTabs:true,
activeTab:0,
deferredRender:false,
border:false,
listeners: {
tabchange: function(tabPanel, activeTab) {
if (activeTab.title == 'Anmelden') {
win.buttons[0].show();
} else {
win.buttons[0].hide();
}
}
}
}),
buttons:[{
text:'OK',
formBind: true,
hideMode: 'visibility',
handler:function(){
login.getForm().submit({
method:'POST',
waitTitle:'Verbinde',
waitMsg:'Uebertrage Daten',
success:function(){
var redirect = 'index.php';
window.location = redirect;
},

failure:function(form, action){
if(action.failureType == 'server'){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert('Fehler!', obj.errors.reason);
}else{
Ext.Msg.alert('Fehler!', 'Bitte füllen Sie alle erforderlichen Felder aus!' );
}
login.getForm().reset();
}
});
}
}]

});
win.show(this);


});
the problem is that when i call
win.buttons[0].show(); inside the listener of the tab-panel, i get an error like "win is undefined", because i cant see "win" from inside there.
i have tried "this.container" but there is no property "buttons" for that. i dont know how to reach the button-property of my window-object from inside there.
please help me if you know how to, i will really appreciate! :)thanks, humpdi

realjax
22 Dec 2009, 11:57 PM
Give the buttons an id, you can then get to them using Ext.getCmp('id')

humpdi
23 Dec 2009, 2:07 AM
hm, when i do this, firebug tells me "Ext.getCmp("button_login") is undefined". i think the problem is that the button doesnt even exist at this time. because i create the window object, and in there is the listener AND the buttons. so inside the listener i cant get the buttons because the window-object doesnt exist at that time.
thats what i think, i dont know....