Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

how can i disable android auto text field focus

how can i disable android auto text field focus? It says Titanium.UI.TextField blur method will force the field to lose focus. How do I do this? Thanks

— asked June 26th 2011 by travis k
  • android 1.7
0 Comments

3 Answers

  • Travis

    I would expect the following code to work as you expect, but demonstrates the problem you have:

    Ti.UI.backgroundColor = "#FFFFFF";
    
    var win = Ti.UI.createWindow({
      exitOnClose: true
    });
    
    var textField = Ti.UI.createTextField({
      height:60,
      top:60,
      left:30,
      width:250
    });
    
    
    win.add(textField);
    win.open();
    
    win.addEventListener('load', function(){
      textField.blur();
    })
    

    Using the blur method will certainly hide the keyboard if it is showing, but when there is one or more textFields present in a window, it may be native behavior to have at least one with focus.

    I will have to investigate, and get back to you.

    Cheers

    — answered June 27th 2011 by Paul Dowsett
    permalink
    2 Comments
    • event 'load' did not fire. So I used event 'focus'. it fires but window closes and app restarts. I don't understand Titanium.UI.Window softKeyboardOnFocus property works but this dosen't work

      var loginWindow = Ti.UI.createWindow({ 
                              fullscreen:false, 
                              url: 'js/login.js',
                              backgroundColor:'#fff',
                              navBarHidden:true,
                              softKeyboardOnFocus:Titanium.UI.Android.SOFT_KEYBOARD_HIDE_ON_FOCUS
                              });
      

      — commented June 27th 2011 by travis k
    • Hi Paul,

      Any update on this issue ? I'm facing the same problem. While your solution works for forcing the keyboard to hide on load, there is still a moment when you can see it before it disappear, making the whole thing feel odd.
      Something strange is that in the kitchen sink "Hide Soft Keybarad" screen, it does not reproduce.

      — commented August 4th 2011 by Jerome Velociter
  • I ran into a similar problem. I wanted my textfield not to have the keyboard on window focus, but the textfield should show keyboard only when tapped. This is a behaviour that is there in iOS.

            txtFieldSearch.softKeyboardOnFocus = Ti.UI.Android.SOFT_KEYBOARD_HIDE_ON_FOCUS;
            txtFieldSearch.addEventListener('click',function(e)
            {
                txtFieldSearch.setSoftKeyboardOnFocus(Ti.UI.Android.SOFT_KEYBOARD_SHOW_ON_FOCUS);
                txtFieldSearch.focus();
            });
    

    Made my code work, simple and straight forward

    — answered September 6th 2013 by Abhishek Sharma
    permalink
    0 Comments
  • Ran into the same issue today with Android auto focusing a text field on window load.

    Here's the crude work around that worked for me:

    //track your inputs on window into array, e.g. 
    var inputs = [];
    
    //add inputs, etc...
    
    Ti.UI.currentWindow.addEventListener('focus',function(e){
        setTimeout(function(){
            for(var i in inputs){
                inputs[i].blur();
            }
        },1000);//adjust as needed
    });
    
    — answered May 25th 2012 by Dan Boorn
    permalink
    1 Comment
    • //UPDATE -- This seems to catch the input focus better, sad, but it seems to work...
      
      var inputs = [];
      
      //add inputs, etc...
      
      Ti.UI.currentWindow.addEventListener('focus',function(e){
          for(var i in inputs){
              setTimeout(function(){
                  inputs[i].blur();        
              },1000);//adjust as needed
          }
      });
      

      — commented May 25th 2012 by Dan Boorn
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.