Dynamically setting passwordMask in Titanium

Unfortunately, you cant do this. According to the docs on Ti.UI.TextField in the fine print;

Note: on iOS, passwordMask must be specified when this text field is created.

Its not all bad news though, there are a couple ways you can approach this,

one option is to make the password mask yourself, by listening to the change event:

var theStoredPassword = '';
$.password.addEventListener('change', function(e) {
    var newpass = e.source.value; 

    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
    $.password.value = new Array(newpass.length + 1).join('●');

One thought on “Dynamically setting passwordMask in Titanium

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: