Skip to content

Instantly share code, notes, and snippets.

@srahim
Created August 7, 2012 23:03
Show Gist options
  • Save srahim/3290368 to your computer and use it in GitHub Desktop.
Save srahim/3290368 to your computer and use it in GitHub Desktop.
TextField Test case
var win = Ti.UI.createWindow();
var l = Titanium.UI.createLabel({
text:'Text area tests.',
font:{fontSize:14},
left:10,
top:10,
width:300,
height:'auto'
});
win.add(l);
var tf1 = Titanium.UI.createTextField({
value:'rounded border',
height:35,
top:10,
left:10,
right:60,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(tf1);
//
// Focus text area
//
var b1 = Titanium.UI.createButton({
title:'Focus',
height:40,
width:200,
top:140
});
win.add(b1);
b1.addEventListener('click', function()
{
tf1.focus();
});
//
// Blur text area
//
var b2 = Titanium.UI.createButton({
title:'Blur',
height:40,
width:200,
top:190
});
win.add(b2);
b2.addEventListener('click', function()
{
tf1.blur();
});
//
// Hide/Shw text area
//
var b3 = Titanium.UI.createButton({
title:'Hide/Show',
height:40,
width:200,
top:240
});
win.add(b3);
var visible=true;
b3.addEventListener('click', function()
{
if (visible)
{
tf1.hide();
visible=false;
}
else
{
tf1.show();
visible=true;
}
});
var b5 = Titanium.UI.createButton({
title:'Toggle "editable"',
top:300,
height:40,
width:200
});
win.add(b5);
b5.addEventListener('click',function(){
tf1.editable = !tf1.editable;
});
//
// Text area events
//
tf1.addEventListener('change',function(e)
{
l.text = 'change fired, value = ' + e.value + '\nfield value = ' + ta1.value;
});
tf1.addEventListener('blur',function(e)
{
l.text = 'blur fired, value = ' + e.value;
});
tf1.addEventListener('focus',function(e)
{
l.text = 'focus fired, value = ' + e.value;
});
tf1.addEventListener('return',function(e)
{
l.text = 'return fired, value = ' + e.value;
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment