PDA

View Full Version : validation problem



sagardash
5 Aug 2010, 1:23 AM
Hi

I have two textfield username and password.
If both fields are empty then no problem ..
But i want if user enter value into one field then the second textfiled should be mandatory ...

can someone please help me regarding this...

Thanks

Condor
5 Aug 2010, 2:58 AM
var username = new Ext.form.TextField({
fieldLabel: 'Username',
name: 'username'
});
var password = new Ext.form.TextField({
fieldLabel: 'Password',
name: 'password'
inputType: 'password',
validator: function(v){
this.allowBlank = !username.getValue();
return true;
}
});

sagardash
5 Aug 2010, 3:41 AM
how it will work .... am i need to call validator in save button...

Condor
5 Aug 2010, 3:50 AM
Check formPanel.getForm().isValid() in your Save button handler.

isValid() will be called automatically when you do a formPanel.getForm().submit({...}).

sagardash
5 Aug 2010, 4:04 AM
This is my code...
i am not getting any message... for validation ... please correct it ...plz


var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
url:'save-form.php',

items: [{
xtype: 'textfield',
fieldLabel: 'First Name',
name: 'first',
id:'first',
//allowBlank:true


},{
xtype: 'textfield',
fieldLabel: 'Pass11',
name: 'last',
id:'last',
inputType: 'password',
validator: function(v){
this.allowBlank = !first.getValue();
return true;
}
}],

buttons: [{
text: 'Save',
handler:function(){
simple.getForm().submit;
}
},{
text: 'Cancel',
handler:function(){
}
}]
});
simple.render(document.body);

Condor
5 Aug 2010, 5:37 AM
'first' is the name of a field. That doesn't automatically mean that it is available as a variable!

validator: function(){
var first = simple.getForm().findField('first');
this.allowBlank = !first.getValue();
return true;
}

sagardash
5 Aug 2010, 9:08 PM
Thanks a lot condor.... it helped me a lot ....

THANKS