PDA

View Full Version : Focus on Primary Window



rehanazher
26 Jul 2009, 5:19 AM
Hi All,

I have two windows, one as Primary window (with Form Elements) and other as Secondary window showing some results of the user input. Secondary Window is displayed based on the User's selection for some combo boxes.

I am using afterRendered to shift the focus back to my Primary window's required element , it is working fine and giving me the required result. But Firebug reports an error every time focus is shifted back. Error is:
this.manager is undefined
this is online number 36758 of ext-all-debug.js

Below is my code if some one can help to check where I am making mistake:


function newDevice(){
var dspop = new Ext.data.Store({
autoDestroy: true,
reader: new Ext.data.JsonReader({
fields: ['popid', 'popname'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'include/getPoP.php'
})
});
dspop.load();
var dseracks = new Ext.data.Store({
autoDestroy: true,
reader: new Ext.data.JsonReader({
fields: ['rackid', 'rackName', 'racktype','rackUCount'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'include/geteRack.php'
})
});
dseracks.load({params: {id1: 0}});
var newDeviceForm = new Ext.FormPanel({
labelWidth:90,
url:'process.php',
region: 'center',
frame:true,
title:'Add New Rack',
defaultType:'textfield',
monitorValid:true,
items:[{
xtype: 'combo',
name: 'popName',
valueField: 'popid',
triggerAction: 'all',
id: 'cmbpname',
hiddenName: "popID",
emptyText:'Select PoP Name...',
labelStyle: 'font-weight:bolder;',
fieldLabel: 'PoP Site',
mode: 'local',
store: dspop,
editable: false,
allowBlank: false,
displayField:'popname',
width: 120,
listeners: {
select: function(f,r,i){
a=Ext.getCmp('cmbpname').getValue();
var rackcombo = Ext.getCmp('cmbrname');
rackcombo.store.reload({params:{id1: a}});
}
}
},{
xtype: 'combo',
name: 'rackName',
valueField: 'rackid',
triggerAction: 'all',
id: 'cmbrname',
hiddenName: "rackID",
emptyText:'Select Rack...',
labelStyle: 'font-weight:bolder;',
fieldLabel: 'Rack Name',
mode: 'local',
store: dseracks,
editable: false,
allowBlank: false,
displayField:'rackName',
width: 120,
listeners: {
select: function(f,r,i){



var sideWin = new Ext.Panel({
layout: 'fit',
border: 0,
title: 'Rack Information',
html: "Hello",
height: 475,
width: 300,
items:[

]
//renderTo: document.body()
});
var win2= new Ext.Window({
layout:'fit',
width:450,
height: 560,
x: 950,
y: 58,
closable: false,
resizable: false,
plain: true,
border: false,
items: [sideWin],
afterRender: function(){
Ext.getCmp('dName').focus();
}
});
win2.show();
}
}


},{
xtype: 'textfield',
fieldLabel: 'Device Name',
id: 'dName',
labelStyle: 'font-weight:bolder;',
name: 'dName',
allowBlank: false,
width: 200
}
],
buttons:[{
text:'Add',
formBind: true,
handler:function(){
Newpop.getForm().submit({
method:'POST',
// waitTitle:'Connecting',
// waitMsg:'Sending data...',
success:function(){
Ext.Msg.alert('Status', 'PoP Added Sucessfully!', function(btn, text){
if (btn == 'ok'){
Newpop.getForm().reset();
}
});
},
failure:function(form, action){
if(action.failureType == 'server'){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.show({
title: 'Error!',
msg: 'Add New PoP Failed! <br> '+obj.errors.reason,
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
fn: function(btn){
Ext.getCmp('paddName').focus(true);
}
});
}else{
Ext.Msg.alert('Warning!', 'Server is unreachable : ' + action.response.responseText);
}
}
});
}
},{
text:'Reset',
formBind: true,
handler: function(){
Newpop.getForm().reset();
}

},{
text:'Close',
handler: function(){
win.hide();
win.destroy();
}

}]
});
var win = new Ext.Window({
layout:'fit',
width:350,
height: 260,
closable: false,
resizable: false,
plain: true,
border: false,
items: [newDeviceForm]
});
win.show();


}

Here cmbrname is linked to cmbpname i.e. it is populated based on selected value in cmbpname.

Then secondary window is displayed after user select a value in cmbrname. on afterRendered focus is shifted back to priamry window textfield dName.

mjlecomte
26 Jul 2009, 8:21 AM
Looks like you override the prototype afterRender event instead of adding a listener with a handler.

rehanazher
26 Jul 2009, 9:45 AM
Hi can you help we some code for this listener, or it will be just simple listener like:

listeners:
<mu code>.............


like my combo listeners.

mjlecomte
26 Jul 2009, 12:48 PM
Listeners...like anything else I suppose.

Really, to get help in forums I highly suggest stripping your code down to the absolute minimum to show the problem parts. With so much code that is irrelevant to your question you scare off too many potential helpers.

I would think your code would have two windows and some trigger or field or something that switches focus. The rest is application specific that doesn't really matter does it?

rehanazher
26 Jul 2009, 5:54 PM
Thanks , I got it.

Just required to wrap my afterRendered in listeners block. i.e.


listeners: {
afterRendered: function(){
<Mycode goes Here...........................>
}
}