GXT KeyListener.componentKeyDown() 立即关闭 MessageBox.alert()

发布于 2024-07-16 03:40:12 字数 434 浏览 3 评论 0原文

在 GXT 中,MessageBox 方法是异步的,这意味着应用程序在显示消息框时不会“锁定”。

我使用 KeyListener 处理表单中的输入按键(以提高可用性,即允许通过输入键提交表单),然后在应用程序处理用户凭据时禁用表单字段。 如果它们不正确,我会显示 MessageBox.alert(),然后重新启用表单字段。 但是,由于 alert() 立即返回,因此表单字段立即再次可用,从而允许用户在不关闭警报的情况下输入数据。

解决方案是在 alert() 中使用回调; 但是,按 Enter 按键不仅会导致表单提交,还会导致警报立即消失(就好像表单和消息框都在处理 Enter 键一样)。 如何保持警报框打开,直到用户再次按 Enter 键或单击“确定”按钮?

In GXT, MessageBox methods are asynchronous, meaning that the application does not "lock up" while the message box is displayed.

I using a KeyListener to process enter key presses in a form (to increase usability, i.e., allowing the form to be submitted by the enter key) and subsequently disabling the form fields while the application processes the user's credentials. If they are incorrect, I show a MessageBox.alert() and then re-enable the form fields. However, since alert() returns immediately, the form fields are immediately made available again, allowing the user to input data without closing the alert.

The solution is to use a callback in alert(); however, the enter keypress not only causes the form to submit, but also causes the alert to immediately dismiss (as if both the form and the message box are processing the enter key). How do I keep the alert box open until the user presses enter a second time or clicks the "Ok" button?

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

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

发布评论

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

评论(1

初雪 2024-07-23 03:40:12

关键是 GWT

此类允许您在所有当前挂起的事件处理程序完成后使用 addCommand(Command)addCommand(IncrementalCommand) 方法执行代码。 当您需要在当前堆栈上下文之外执行代码时,这非常有用。

if(!validate())
{
    DeferredCommand.addCommand(new Command() {
        public void execute() {
            MessageBox.alert("Error", "You must enter a username and password.", alertListener);
            return;
        }
    });
}

The key is DeferredCommand provided by GWT:

This class allows you to execute code after all currently pending event handlers have completed, using the addCommand(Command) or addCommand(IncrementalCommand) methods. This is useful when you need to execute code outside of the context of the current stack.

if(!validate())
{
    DeferredCommand.addCommand(new Command() {
        public void execute() {
            MessageBox.alert("Error", "You must enter a username and password.", alertListener);
            return;
        }
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文