Skip to content

Instantly share code, notes, and snippets.

@adampax
Created October 20, 2011 17:59
Show Gist options
  • Save adampax/1301813 to your computer and use it in GitHub Desktop.
Save adampax/1301813 to your computer and use it in GitHub Desktop.
Simple Titanium form saved in an array with return key eventlistener moving to the next field
Ti.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
title : 'test'
});
var arrayLength = 5
var fields = new Array(arrayLength);
for( i = 0; i < arrayLength; i++) {
fields[i] = Ti.UI.createTextField({
id : i,
height : 40,
width : 100,
hintText : 'Field ' + i,
value : '',
top : i * 50,
returnKeyType : i != arrayLength - 1 ? Titanium.UI.RETURNKEY_NEXT : Ti.UI.RETURNKEY_DONE,
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
fields[i].addEventListener('return', function(e) {
var j = e.source.id;
if(j != arrayLength-1) {
fields[j + 1].focus();
} else {
alert('Done');
}
});
win.add(fields[i]);
};
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment