Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting focus on a Popup's textInput control

I'm trying to have a popup window with an immediately editable TextInput. This means that the user should be able to type inside the TextInput once the popup is displayed.

The problem is that I can't focus on the textInput. What happens is that when pressing a key for the first time, no text is inserted, only after a second key is pressed does the component gain focus and the user is able to type. For instance, typing "test" once the popup opened results in "est" being displayed...

For some reason the component only gains focus when the user explicitly clicks on it or types something. Programmaticaly setting the focus does not work.

Any ideas/suggestions?

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns="mog.miss.component.*" xmlns:mx="http://www.adobe.com/2006/mxml" >

<mx:Script>
    <![CDATA[
        import mx.managers.IFocusManagerComponent;

        private function focus():void{
            focusManager.setFocus(commentTextInput as IFocusManagerComponent);
            commentTextInput.setSelection(commentTextInput.text.length,commentTextInput.text.length);
        }

    ]]>
</mx:Script>
<mx:TextInput id="commentTextInput" creationComplete="{focus()}" />

</mx:Panel>
like image 793
Tiago Pereira Avatar asked Nov 06 '22 10:11

Tiago Pereira


1 Answers

The problem was that I was triggering the popup call with the F10 key. The F10 is system reserved... it did trigger the handler and the popup was created but somehow the application lost focus. Using another key fixed it. The only reserved key is F10. More about that

like image 156
Tiago Pereira Avatar answered Nov 08 '22 12:11

Tiago Pereira