简体   繁体   中英

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>

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

in my case i just implemented IFocusManagerContainer in my custom component and everything worked fine

private var _defaultButton:IFlexDisplayObject = / default component /;

    public function get defaultButton():IFlexDisplayObject{
        return _defaultButton;
    }
    public function set defaultButton(value:IFlexDisplayObject):void{
        _defaultButton = value;
        ContainerGlobals.focusedContainer = null;
    }

It depends on how you try to do it. What works for me is handling the creationComplete Event of the popup:

private function onCreationComplete():void 
{
    focusManager.setFocus(this.mytextInput as IFocusManagerComponent);
}

PS: The "handler" in the example is added via mxml so it has no parameters.

Here's what works for me. In the creationComplete event of the pop up window:

private function onCreationComplete():void
{
  callLater(this.commentTextInput.setFocus);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM