Titanium Community Questions & Answer Archive

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

start with focus on a textarea.

I'm having a heck of a time putting focus on a textarea immediately when the app loads.

I've created event listeners and tried to leverage existing ones.

I thought it was working once with the below - but either I was wrong - or it's stopped working:


Titanium.UI.addEventListener('initbox', function(e)
{
    tf1.focus();
});

window.add(view_input);
window.open({fullscreen:true});
Titanium.UI.fireEvent('initbox');

I've also tried to create a window event listener and fire that - but had the same result… nothing.

Any thoughts?

Thanks folks!

— asked April 18th 2010 by Doug Meade
  • event
  • eventlistener
  • focus
  • onload
  • textarea
0 Comments

2 Answers

  • Accepted Answer

    var m = Titanium.UI.createWindow({
        title: "Log in",
        width: 200,
        modal: true
    });
    
    var t = Titanium.UI.createTextField({
        color:'#336699',
        height:35,
        top:50,
        left:50,
        width:250,
        borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    
    m.add(t);
    
    m.addEventListener("open", function(event, type) {
        t.focus();
    });
    
    m.open({
        modal:true,
        modalStyle: Ti.UI.iPhone.MODAL_PRESENTATION_FORMSHEET
    });
    

    I feel like I tried this about a thousand times, but it might have been some combination of ordering changes that suddenly made it work. In any case, this is how I'm getting to happen – a modal window slides up, text area is focused, keyboard slides up with it. I'm still fighting the width of the modal window. I want something more like the email window at only 80% width.

    Hope this helps…

    nz

    — answered April 18th 2010 by Nathan Ziarek
    permalink
    0 Comments
  • I have a search box in my app this is what I used.

    search.addEventListener('change', function(e)
    {
       my.value // as user types user types
    });
    search.addEventListener('return', function(e)
    {
       search.blur();
    });
    search.addEventListener('cancel', function(e)
    {
       search.blur();
    });
    

    tf1.Titanium.UI.addEventListener('initbox', function(e)
    {
    tf1.focus();
    }

    — answered April 18th 2010 by Jeffrey Messick
    permalink
    0 Comments
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.