Text Field Focus Breaks When Window is Closed and Reopened
I was silently hoping this would get fixed by 1.4 but it didn't. I don't usually bother submitting bug reports anymore because they get no attention but I guess 50k 'active' developers didn't see this one…or something.
This is reproducible in two apps that make use of textField.focus().
Create a window with a text field in it.
Slap a 'focus' or 'open' event listener on the window that forces focus on the testField.
Open this window.
The first time, the text field will have focus and show the keyboard.
Close the window.
Open the window.
The second time, the text field will ignore focus.
The event listener definitely fires. Focus simply gets ignored. I even went so far as to add a button that calls focus() on the text field…tapping the button does nothing.
At this point, it is impossible to programatically give focus to the text field…the only way is to manually tap the text field. A tap on the text field will give it focus and bring up the keyboard…but nothing else will.
4 Answers
-
Put a small delay between the focus of the textField and the opening of the window.
the_win.addEventListener('open', function() { setTimeout( function(){the_text_field.focus()} , 50 ); })
This worked for me on an iPad popover that had a textarea in it.
-
In fact, there's a number of things that simply stopped working between 1.3.2 (the 1.4 RC1 release) and 1.4. How the crap does a 'release candidate' change so much as to break things? It's a release candidate!
One thing's for sure, the Appcelerator guys keep me on my toes, constantly rewriting code to circumvent new SDK bugs. Unfortunately, this sometimes involves less than adequate solutions which forces me to rewrite when (if) the bug is fixed in later versions.
-
Maybe the 50k active developers didn't see this one, because it's not happening to them? Could be easier to troubleshoot if you posted a piece of code that reproduces the bug :)
How are you creating the new window, is it running in the same context or in a separate .js file? Do you use a tab group, navigation group?
I created a small sample to try and reproduce the bug, but the text field focuses reliably every time, no matter how many times I close and reopen the window.
I'm using SDK 4.0.1, tested on Titanium 1.4.0 and 1.4.1 continuous build.
Code: app.js, newWindow.js
-
This is broke for me as well, did you ever figure out a work around? I am developing for android, 1.2.1 and 1.4.2