I am new to Ext JS, i do have a password field and a SHOW button adjacent to it. Need to convert the masked password to text field when clicked on SHOW. Currently we just display the password in another pop up window when clicked on SHOW. How do i get the field password in order to change its xtype to text form password?
Form.js
{xtype: 'displayfield', value: 'Password ', width: '16%', style: 'text-align: right', preventMark: 'true'},
{
xtype: 'textfield',
name: 'password',
inputType: 'password',
cls: 'textfield-with-border'
},
{
xtype: 'button',
text: 'Show',
buttonAlign: 'left',
formBind: true,
handler: this.onShowPassword,
style: 'margin-left: 5px',
cls: '',
scope: this
},
onShowPassword : function(btn, ev) {
var x = this.getForm().findField('password');
x.xType = "text";
}
Previous onShowPassword() function is :
onShowPassword : function(btn, ev) {
//encode form values into JSON data
var jsonUpdate = Ext.util.JSON.encode(fields);
//Encoding for the password for html to take it as a plain text
var encodedPassword = Ext.util.Format.htmlEncode(fields.password);
Ext.Ajax.request({
scope: this,
url: this.urlBase + 'xyz',
headers: this.createTokenHeader(),
method: 'POST',
jsonData: jsonUpdate,
success: function(response){
//decode JSON response
var form = Ext.decode(response.responseText);
Ext.Msg.alert("info", "Password is: "+encodedPassword);
setTimeout(function(){
Ext.Msg.hide();
},15000);
},
failure: function(response){
var error = Ext.decode(response.responseText);
Ext.Msg.alert("Error", "Some error occurred while showing the password, please try again after some time");
}
});
},
Tried code: (Did not work)
var x = this.getForm().findField('password');
var passwordFieldDom = x.getEl().dom;
var typeAttribute = (passwordFieldDom.type === 'password'? 'text': password');
this.getForm().findField('password').getEl().dom.type === typeAttribute;
The above code does change the type from password to text but it does not reflect on the UI as non masked password, after this the password still comes in masked.
I need to make change in onShowPassword()
. Let me know how can i do that.