Skip to content

Instantly share code, notes, and snippets.

@grantges
Created July 17, 2012 22:55
Show Gist options
  • Save grantges/3132699 to your computer and use it in GitHub Desktop.
Save grantges/3132699 to your computer and use it in GitHub Desktop.
TextField - Max Length and Event Handling
var win = Ti.UI.createWindow({layout: 'vertical', backgroundColor:'#fff'});
var textField = Ti.UI.createTextField({
height: Ti.UI.SIZE,
width: '90%',
font: {fontSize: 20},
softKeyboardOnFocus: Ti.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS
});
textField.addEventListener('return', function(e){
Ti.API.info('RETURN EVENT');
if(e.source.value.length > 5) {
alert('Max Length can not exceed five characters');
e.source.value = e.source.value.substring(0,5);
e.source.focus();
}
});
textField.addEventListener('change', function(e){
if(isNaN(e.value)) {
alert('Only Numbers Please')
}
});
win.add(textField);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment