PDA

View Full Version : Get child window in focus on load



nikita.navale
29 Feb 2016, 6:45 AM
Hi,

On load of the window, the button shortcuts inside window are not enabled until you click somewhere inside the window.
The window has viewport as its main (base) element i.e viewport is rendered to Ext.getBody();

Could there be anything that I am missing here?
I am calling following code at the end of on-ready





//need to set the focus somewhere in the window to listen key events
Ext.getCmp('create-pack').focus('', 20);

var keymap = new Ext.KeyMap(viewport.getEl(), [{
key: Ext.EventObject.F9,
ctrl : false,
fn: function(key, e) {
if((!Ext.isDefined(windowCreatePack) || (Ext.isDefined(windowCreatePack) && !windowCreatePack.isVisible())) &&
Ext.isDefined(Ext.getCmp('create-pack'))
&& Ext.getCmp('create-pack').isVisible()
&& !Ext.getCmp('create-pack').disabled){

createPackHandler();
}
},
scope: this
},{
key: Ext.EventObject.F2,
ctrl : true,
fn: function(key, e) {
if(Ext.isDefined(parent.taskWin.getBottomToolbar().getComponent("complete")) &&
parent.taskWin.getBottomToolbar().getComponent("complete").isVisible()){
setTaskSuccessful();

}
},
scope: this
},{
key: Ext.EventObject.ESC,
ctrl : false,
fn: function(key, e) {
if(Ext.isDefined(parent.taskWin.getBottomToolbar().getComponent("cancelButton")) &&
parent.taskWin.getBottomToolbar().getComponent("cancelButton").isVisible()){

parent.closeWindowButton(parent.taskWin);
}
},
scope: this
}]);




Thanks!

nikita.navale
1 Mar 2016, 6:57 AM
Hello Everyone,

Any help here would be great!

Thanks!

Gary Schlosberg
1 Mar 2016, 7:55 PM
Does the issue occur if you don't run the code you included?

nikita.navale
2 Mar 2016, 2:43 AM
Hi Gary,


Does the issue occur if you don't run the code you included?

If I comment the entire snippet above, shorcut keys won't run.
If I comment out only the first line (which is supposed to get focus), the page would still behave the same. Have to click somewhere on child screen for keys to work.

Thanks..

nikita.navale
2 Mar 2016, 11:49 PM
There has to be some way to tackle this. Right?
Or Maybe if I can achieve the condition of clicking inside the window to get the control inside window..
Is there a programmatic way to click inside the viewport? I tried button.fireevent(click, <btnCmp>)
But that didn't do anything.

Any help please...

nikita.navale
7 Mar 2016, 1:03 AM
Resolved this issue by a work around. Had to get the focus on a textfield on the child window on load of the final store expected on screen.

Something like this:

//need to set the focus somewhere in the task to listen key events
gridUnpackedItems.store.on( 'load', function( store, records, options ) {
var searchField = Ext.getCmp('gridUnpackedSearchField');
searchField.focus();
});


var keymap = new Ext.KeyMap(viewport.getEl(), [{
..... //keymap definition
}]

That did the trick.

Thanks!