Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
squished18
Posts: 289
Registered: ‎10-17-2008
My Device: Torch 9800
Accepted Solution

.focus() call not working in Playbook 2.0 app

Hello,

 

This is a Playbook 2.0 app. I am trying to call .focus() on a textarea, but nothing happens when I make the call. Strangely, I have a second textarea on another page that is responding properly to the .focus() call.

 

Here is the HTML code for the textarea:

<textarea id='fieldDescription' name='fieldDescription' type='text' style='width:85%;height:1.25em' x-blackberry-focusable='true'></textarea>

 

I have also tried using .click() on the textarea, but I see no effects from this call either. If I perform a manual click, the focus does switch to the textarea correctly. However, I can't seem to get this to happen programatically.

 

I have looked using Web Inspector, but am not seeing any console messages that indicate what the problem might be. Any ideas how to begin to track down where the problem is?

 

Thanks,

 

feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.
Developer
squished18
Posts: 289
Registered: ‎10-17-2008
My Device: Torch 9800

Re: .focus() call not working in Playbook 2.0 app

I'm finding that when the .focus() call is made, I get two triggers of the field's blur() event. Is this normal?

 

Thanks,

 

feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.
Developer
squished18
Posts: 289
Registered: ‎10-17-2008
My Device: Torch 9800

Re: .focus() call not working in Playbook 2.0 app

I tried tracing where the focus lies before calling .focus(), but I am getting the error message:

   TypeError: 'undefined' is not an object (evaluating 'blackberry.focus.getFocus')

 

Here's the code where I try to set the focus.

        if (($('#fieldDescription').val().length > 0) == false)
        {
            console.log("screenChecklist : blackberry.focus.getFocus() = " + blackberry.focus.getFocus());
            $('#fieldDescription').focus();
        }; // end if

 Thanks,

 

feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.
Trusted Contributor
Magnetic_dud
Posts: 121
Registered: ‎03-06-2012
My Device: Z10

Re: .focus() call not working in Playbook 2.0 app

for me it works
i do this:

document.getElementById("id").focus();
Please use plain text.
Developer
squished18
Posts: 289
Registered: ‎10-17-2008
My Device: Torch 9800

Re: .focus() call not working in Playbook 2.0 app

Thanks for the reply Magenetic_dud:

 

I have found a workaround for the issue by delaying the .focus() call:

setTimeout(function () {$('#fieldDescription').focus();}, 200);

At this time I am concluding that the issue was a DOM rendering issue that was likely caused because when the .focus() call was being made my changes to the DOM had not been fully loaded yet.

 

Thanks,

feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.