PDA

View Full Version : [SOLVED] FormPanel focus field clearInvalid only works once?



PranKe01
12 Jan 2010, 4:06 AM
Hi guys,

when I create a Window with a FormPanel, I want that a field is focused and the invalid marks should be removed. When I click Enter, the form is submitted. I do it like this:

function loginToSystem:

var login = new Ext.FormPanel({
frame: true,
defaultType: 'textfield',
monitorValid: true,
items: [{
fieldLabel: 'Password',
name: 'loginPassword',
inputType: 'password',
allowBlank: false,
id: 'passwordID'
}],
buttons: [{
text: 'Forgot PW',
handler: function(){
loginwin.close();
forgotPassword();
}
}, {
text: 'Login',
id: 'loginForm',
formBind: true,
handler: function(){
loginwin.close();
//...
}
}],
listeners: {
afterlayout: function(){
login.getForm().findField("passwordID").focus();
login.getForm().clearInvalid();
}
},
keys: [{
key: [10, 13],
fn: function() {
Ext.getCmp("loginForm").handler.call(Ext.getCmp("loginForm").scope);
}
}]
});

var loginwin = new Ext.Window({
layout: 'fit',
title: 'Login',
width: 325,
height: 140,
closable: false,
resizable: false,
draggable: false,
modal: true,
plain: true,
border: false,
items: [login]
});

loginwin.show();

That code works, if you run it. The invalid markers are removed and the password field is focused. When I click on the forgot password button, another window should open and show another field which also should be focused and the invalid marks should be removed - but it does not!

function forgotPassword:

var forgotpw = new Ext.FormPanel({
frame: true,
defaultType: 'textfield',
monitorValid: true,
items: [{
fieldLabel: 'E-Mail',
name: 'forgotEmail',
allowBlank: false,
vtype: 'email',
id: 'emailID'
}],
buttons: [{
text: 'Back',
handler: function(){
forgotpwwin.close();
loginToSystem();
}
},{
text: 'Passwort anfordern',
id: 'requestPasswordForm',
formBind: true,
handler: function(){
forgotpwwin.close();
loginToSystem();
}
}],
listeners: {
afterlayout: function(){
forgotpw.getForm().findField("emailID").focus();
forgotpw.getForm().clearInvalid();
}
},
keys: [{
key: [10, 13],
fn: function() {
Ext.getCmp("requestPasswordForm").handler.call(Ext.getCmp("requestPasswordForm").scope);
}
}]
});

var forgotpwwin = new Ext.Window({
layout: 'fit',
title: 'Forgot password',
width: 325,
height: 110,
closable: false,
resizable: false,
draggable: false,
modal: true,
plain: true,
border: false,
items: [forgotpw]
});

forgotpwwin.show();

In this function the invalid marks remain and the field is not focused. If I click on back, and the login window is opened again, the invalid marks for the login window also are not removed and the field is not focused anymore...

Is there something wrong with my code, or is it a bug which is new in Ext3.1? Whenever I create a new window and want to focus something, it does not work :-?

PranKe01
24 Jan 2010, 7:25 AM
Am I the only one who got this problem?

PranKe01
10 Feb 2010, 3:58 AM
I updated to ExtJS 3.1.1 today, and now it works well :)