PDA

View Full Version : onclick button , password field value into string value



nakul_sagar
10 Sep 2012, 5:16 AM
hi everyone...

i want to know how to do this .. onclick button , password field value should show normal string value. pls help me..

thanks in advance

sword-it
10 Sep 2012, 6:20 AM
Hi Nakul,
I am giving you an example in which I take on textfield & one button. On button click I am toggling the type of textfield. The following code may solve your problem:



Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
renderTo: Ext.getBody(),
items: [
{
xtype: 'textfield',
name: 'password',
fieldLabel: 'Password',
inputType: 'password'
},
{
xtype: 'button'
, text: 'Toggle the type of textfield'
, handler: function(){
var type = this.previousSibling().inputEl.dom.type;
if(type == 'text'){
this.previousSibling().inputEl.dom.type = 'password';
}
else{
this.previousSibling().inputEl.dom.type = 'text';
}
}
}
]
});

nakul_sagar
10 Sep 2012, 10:24 PM
thank u so much.. i got an idea from your code and solved :)

code:

new Ext.Application({
name: 'show_password',
launch: function(){

this.viewport = new Ext.form.FormPanel({
title: 'Contact Info',
//width: 300,
renderTo: Ext.getBody(),
items: [
{
xtype: 'passwordfield',
name: 'password',
label: 'Password',
// inputType: 'password',
id: 'pass'
},
{
xtype: 'textfield',
name: 'password',
label: 'Password',
hidden: true,
// inputType: 'password',
id: 'text'
},
{
xtype: 'button',
text: 'Toggle the password',
handler: function(){

if (Ext.getCmp('text').isHidden()) {
Ext.getCmp('text').show();
Ext.getCmp('text').setValue(Ext.getCmp('pass').getValue());
Ext.getCmp('pass').hide();
}else{
Ext.getCmp('pass').show();
Ext.getCmp('text').hide();
}


}
}
]
});

}
});