将焦点设置在 Popup 的 textInput 控件上

发布于 2024-09-11 18:02:45 字数 877 浏览 13 评论 0原文

我正在尝试创建一个带有可立即编辑的 TextInput 的弹出窗口。这意味着一旦显示弹出窗口,用户应该能够在 TextInput 中输入内容。

问题是我无法专注于文本输入。发生的情况是,当第一次按下某个键时,不会插入任何文本,只有在按下第二个键后,组件才会获得焦点,用户才能键入。例如,在弹出窗口打开后键入“test”会导致显示“est”...

出于某种原因,该组件仅在用户明确单击它或键入某些内容时才会获得焦点。以编程方式设置焦点不起作用。

有什么想法/建议吗?

代码:

<?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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

别挽留 2024-09-18 18:02:45

问题是我用 F10 键触发了弹出调用。 F10 是系统保留的...它确实触发了处理程序并创建了弹出窗口,但不知何故应用程序失去了焦点。使用另一把钥匙修复了它。唯一的保留键是 F10。 更多信息

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

诠释孤独 2024-09-18 18:02:45

这取决于你如何尝试去做。对我有用的是处理弹出窗口的creationComplete事件:

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

PS:示例中的“处理程序”是通过mxml添加的,因此它没有参数。

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.

庆幸我还是我 2024-09-18 18:02:45

这对我有用。在弹出窗口的creationComplete事件中:

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

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

private function onCreationComplete():void
{
  callLater(this.commentTextInput.setFocus);
}
欢烬 2024-09-18 18:02:45

就我而言,我刚刚在自定义组件中实现了 IFocusManagerContainer,一切正常

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;
    }

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文