PDA

View Full Version : [SOLVED] HELP with default focus on text field



sonoro
28 Dec 2010, 9:28 AM
Hi guys!
I'm making my first application with Sencha, but I can not work as I want
Do not know how to do these two things:
1) position the focus on the text field. When I say focus I really mean that the cursor should be placed in the first field.
2) capture the enter keyin this field.

I have a tabPanel which has one textfield (name: 'cbarras'). I would like to set the cursor in this field when the tabPanel is rendered.

I have tried to use Ext.getCmp('cbarras').focus(); to position the cursor in the field. Unfortunately does nothing. I have first to select the text field with the mouse.

Once have written in, immediately capturar the 'enter' key to control the workflow customization my app

Does anyone have any suggestion how I can do this?
help please....and thanks

My code:


function getKey(e){
if(!e)
e=window.event;
if(e.keyCode)
code=e.keyCode;
else
code=e.which;
if(code===13){
alert('enter click');
}
}

Ext.setup({
onReady: function() {
new Ext.Panel({
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
items: [
{
xtype: 'form',
id: 'MyForm',
items: [{
xtype: 'fieldset',
items: [{
xtype: 'textfield',
id: 'cbarras',
name: 'cbarras',
required: true,
listener:{
change : function() {
alert('hola');
getKey(event);
}
}
}]
}]
}],
listeners: {
render: function() {
//MyForm.items.get(0).focus();
Ext.getCmp('cbarras').focus();
},
}// EO listeners: {}
});
}
});

sonoro
30 Dec 2010, 3:48 AM
I've had solution for my above related questions:

Place focus on a specific text field at beginning and capture 'Enter' key in this field, I did it with both listener ('afterrender' & 'keyup') on the object testfield:


xtype: 'textfield',
id: 'cbarras',
name: 'cbarras',
listeners: {
afterrender: function(){
Ext.getCmp("cbarras").focus();
},
keyup: function(textbox, event) {
if(event.browserEvent.keyCode==13){
alert('enter push');
}
}
}