PDA

View Full Version : markInvalid



hello
19 Nov 2009, 1:21 AM
I am using up keyevents to validate an email and email confirmation fields, the strange thing is that when I call form.markInvalid('msg'), only email gets marked invalid, email confirmation is not marked....
any idea?


new Ext.form.TextField({
id: 'email',
name: 'email',
fieldLabel: 'Email',
allowBlank: false,
minLength: 3,
maxLength: 64,
vtype: 'email',
enableKeyEvents:true/*,
validator: function(v){
if (Ext.form.VTypes['email'](v) !== true) {
return Ext.form.VTypes['emailText'];
}
return true;

},
initialField: 'emailConfirmation'*/
}), new Ext.form.TextField({
id: 'emailConfirmation',
name: 'emailConfirmation',
fieldLabel: 'Confirm Email',
allowBlank: false,
minLength: 2,
maxLength: 64,
vtype: 'email',
enableKeyEvents:true,/*
validator: function(v){
if (Ext.form.VTypes['email'](v) !== true) {
return Ext.form.VTypes['emailText'];
}
return true;

},
initialField: 'email',*/
listeners:{
keyup:function(thisfield, event){

if(thisfield.getValue()!=Ext.getCmp('email').getValue()){

//thisfield.markInvalid("Email Confirmation must be the same as Email.");
thisfield.findParentByType(Ext.ux.Wiz.Card).getForm().markInvalid({
'emailConfirmation':"Email Confirmation must be the same as Email.",
'email':"Email Confirmation must be the same as Email."
});

}
}
}

Condor
19 Nov 2009, 2:23 AM
It is marked, but Ext.form.TextField also uses the keyup event for it's own validation (which clears the error again).

Instead you should write a validator method that returns the error for the field and also marks the other field, e.g.

validator: function(value){
var otherField = Ext.getCmp('email');
if(otherField.getValue() != value){
otherField.markInvalid('Email must be the same as Email Confirmation.');
return 'Email Confirmation must be the same as Email.';
}
return true;
}