04-19-2012 05:33 PM
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,
Solved! Go to Solution.
04-19-2012 05:59 PM
I'm finding that when the .focus() call is made, I get two triggers of the field's blur() event. Is this normal?
Thanks,
04-20-2012 09:38 AM
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,
04-20-2012 05:05 PM
04-20-2012 05:12 PM
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,