Skip to content

Instantly share code, notes, and snippets.

@mauropm
Created July 3, 2014 20:13
Show Gist options
  • Save mauropm/1d15ab3031243740d2af to your computer and use it in GitHub Desktop.
Save mauropm/1d15ab3031243740d2af to your computer and use it in GitHub Desktop.
Textfield with custom passwordMask
var win = Ti.UI.createWindow({
backgroundColor:'white',
});
var tf = Ti.UI.createTextField({
top:10,
left:10,
width:20,
content:'',
maxLength:'3',
borderColor:'black',
});
var tf2 = Ti.UI.createTextField({
top:50,
left:10,
width:20,
content:'',
maxLength:'2',
borderColor:'black',
});
function maskPass(e){
var newpass = e.source.value;
var theStoredPassword = e.source.content;
if(newpass.length < theStoredPassword.length) {
// Character deleted from end
theStoredPassword = theStoredPassword.substring(0, theStoredPassword.length-1);
} else {
// Character added to end
theStoredPassword += newpass.substring(newpass.length-1);
// Mask the text with unicode ● BLACK CIRCLE, 25CF
e.source.value = new Array(newpass.length + 1).join('*');
}
// Set the current content after checking what happened (add or removal of chars)
e.source.content = theStoredPassword;
// Print the current password in clear
Ti.API.info(e.source.content);
// Print the size of the current password
Ti.API.info(e.source.content.length);
}
tf.addEventListener('change',maskPass);
tf2.addEventListener('change',maskPass);
win.add(tf);
win.add(tf2);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment