Skip to content

Instantly share code, notes, and snippets.

@joshualambert
Created January 2, 2014 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshualambert/8222100 to your computer and use it in GitHub Desktop.
Save joshualambert/8222100 to your computer and use it in GitHub Desktop.
hintText shim for Appcelerator's Titanium allowing hintText to be colored. Simply call this function after creating each textfield, and pass the option isPswd boolean if you're dealing with a password field.
// Used to fake hintText coloring to the font color.
// Requires hintText to be defined on the object being passed.
function hintTextShim(uiObject, isPswd) {
uiObject.objectFocus = function () {
if (uiObject.value === uiObject.hintText) {
if (typeof isPswd !== 'undefined' && isPswd === true) {
uiObject.passwordMask = true;
}
uiObject.value = '';
}
};
uiObject.objectBlur = function () {
if (uiObject.value === '') {
if (typeof isPswd !== 'undefined' && isPswd === true) {
uiObject.passwordMask = false;
}
uiObject.value = uiObject.hintText;
}
};
uiObject.addEventListener('focus', uiObject.objectFocus);
uiObject.addEventListener('blur', uiObject.objectBlur);
uiObject.objectBlur(); // Go ahead and set the default hintText.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment