Textfield.value = null - even after filling it in
Ok strange error here. I have been using Titanium for sometime now and this is the first time i have ever seen this happen.
I have a Textfield in a window that asks me to input a username. When I click done it my code should process that username.
But at present i have a bug, in where the value of that textfield is not being retrieved.
var username = Ti.UI.createTextField({
right:10,
left:10,
value:null,
hintText:"Username",
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
});
var un = username.value;
save.addEventListener('click', function()
{
alert(un);
});
I know this should work as I have used it many times before. But this is the first time i have had this bug? anyone else had this before?
1 Answer
-
Accepted Answer
Hi Chris
You simply need to move the un variable inside the eventListener. As you are, you are setting it to the initial username.value contents.
For example,
save.addEventListener('click', function() { var un = username.value; alert(un); });
Hope this helps