Could not type in TextField

You must Login before you can answer or comment on any questions.

I am trying to have two separate windows. Where once you click on a button in window1, it takes you to window2 where you can enter info in a text field. Here when I go to the window2, the text field is not taking any input, after I click on it. The keyboard does not even show up.

Here is the code that switches to window2 from window1 at the click of a button:

simpleButton.addEventListener("click",function(e){
    var eventWin = Ti.UI.createWindow({
        url:'W2.js',
        title:'Events'
    });
   eventWin.open();      
});
Here is the code available on window 2
var win2 = Titanium.UI.createWindow({
    title:"Creating Text Fields and Text Areas",
    backgroundColor:"dcdcdc",
    exitOnClose:true
})
 
var textField1 = Titanium.UI.createTextField({
    top:60,
    height:60,
    width:300,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, //This is a constant that can be used to style textfields in iOS
    hintText:"Hint text"  
});
 
 
win2.addEventListener("click", function(e){
    textField1.blur();  
 
});
 
win2.add(textField1);
 
win2.open();

2 Answers

Since the textField is added to the window, the win2.addEventListener will respond to the click event in the textField. In other words it will blur the text field as soon as you try to focus in it.

Use the source property of e in your click event to determine which element was clicked.

— answered 9 months ago by David Bankier
answer permalink
3 Comments
  • Hi David, I understand what you are saying. It should respond to the "click event" in the textfield. But it is not responding, when I tried to examine the source of e, it seems like that the "click event" is not even registered and there is no response.

    I have tried the code on window2 separately and it works, but when I associate it with the button event from window1 it is not working.

    — commented 9 months ago by Adi Nagarajan

  • Aditiyaa, you're having the problem on Android, right? On iOS, this code should work. I found that excluding the eventlistener for Android is acceptable, since Android users are trained to hit the back button to dismiss the keyboard anyway.

    Not an answer to your question, I know, but hopefully this is still helpful.

    — commented 9 months ago by Shannon Hicks

  • Shannon, I am having this issue with iOS. This is supposed to work as it is.

    — commented 9 months ago by Adi Nagarajan

I just had a brainstorm... try this:

var win2 = Titanium.UI.createWindow({
    title:"Creating Text Fields and Text Areas",
    backgroundColor:"dcdcdc",
    exitOnClose:true
})
 
var focusCatcher = Ti.UI.createView({
    top:0,bottom:0,left:0,right:0
});
win2.add(focusCatcher);
 
var textField1 = Titanium.UI.createTextField({
    top:60,
    height:60,
    width:300,
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED, //This is a constant that can be used to style textfields in iOS
    hintText:"Hint text"  
});
 
 
focusCatcher.addEventListener("click", function(e){
    textField1.blur();  
 
});
 
win2.add(textField1);
 
win2.open();

Your Answer

Think you can help? Login to answer this question!