Form.onSubmit 中的模态窗口或确认框

发布于 2024-10-25 11:55:18 字数 497 浏览 1 评论 0原文

在 Form.onSubmit 中,我可以向该表单添加 SimpleAttributeModifier 吗?实际上,我遇到的情况是,表单的 onSubmit 方法如下所示:

@Override
public void onSubmit() {
    //some code
    if (some_condition) {
        //here I want to show Javascript confirm box or wicket modal window
        //but I can not get any AjaxRequestTarget here to show that modal
        add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
    }
    //some code
}        

它不起作用。有什么办法可以实现这一点吗?谢谢。

In Form.onSubmit can I add a SimpleAttributeModifier to that form? Actually I have a situation where the onSubmit method of the form look like this:

@Override
public void onSubmit() {
    //some code
    if (some_condition) {
        //here I want to show Javascript confirm box or wicket modal window
        //but I can not get any AjaxRequestTarget here to show that modal
        add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
    }
    //some code
}        

It is not working. Is there any way to achieve this? Thank you.

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

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

发布评论

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

评论(1

冷血 2024-11-01 11:55:18

您尝试的方法肯定行不通,因为 onSubmit() 方法没有及时调用。它是提交表单时调用的服务器端方法。为了显示确认对话框,您需要在表单从客户端发送回服务器之前在客户端执行一些 JavaScript。

您需要在呈现 html 时附加 javascript,以便在用户单击提交按钮时调用它。

这当然可以做到。我没有自己的代码,但我认为这个例子 应该让你指向正确的方向。

What you're trying will definitely not work, as the onSubmit() method is not called in time. It is a server-side method called when the form is submitted. In order to show a confirm dialogue, you want some javascript executed on the client before the form is sent back from the client to the server.

You need the attachment of javascript to happen when the html is rendered, so that it's there to be called when the user clicks the submit button.

It can of course be done. I don't have my own code for it handy, but I think this example should get you pointed in the right direction.

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