Wicket ModalWindow:单击模式外部以关闭
我需要向 ModalWindow
添加一个行为,以便当用户在模式之外单击时,如果满足特定条件(在我的 respond()
方法中检查服务器端),模态被驳回。
我尝试根据这个答案实现一些东西。问题是我无法将点击侦听器附加到模式窗口 div,因为在显示模式之前它不会添加到 DOM(该示例将 keyup
附加到文档本身。)
我想扩展 ModalWindow
并通过 getShowJavascript()
添加 JS,但是我没有任何方法将其连接到用于测试的 AbstractDefaultAjaxBehavior.respond()
方法。
I need to add a behavior to ModalWindow
such that when a user clicks outside of the modal, if a certain condition is met (checked server-side in my respond()
method), the modal is dismissed.
I tried implementing something based on this answer. The problem is that I can't attach a click listener to the modal window div because it's not added to the DOM until the modal is shown (the example attaches a keyup
to the document itself.)
I thought of extending ModalWindow
and adding the JS via getShowJavascript()
, but then I don't have any means to connect it to an AbstractDefaultAjaxBehavior.respond()
method for the test.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将行为添加到通过
ModalWindow.setContent()
添加到模式的小部件中,而不是添加到模式中来解决这个问题。当我的小部件添加到模式中时,掩码 div 出现在 DOM 中,然后我可以成功附加单击处理程序。也就是说:
请注意,我有点不稳定地依赖于模态窗口的掩码,该掩码具有名为“wicket-mask-dark”的类;如果您更改
ModalWindow
使用的 CSS 设置,情况可能并非如此。I solved this by adding the behavior not to the modal, but rather to the widget I add to the modal via
ModalWindow.setContent()
. When my widget is added to the modal, the mask div is present in the DOM, and I can then successfully attach a click handler.To wit:
Note that I'm somewhat precariously depending on the modal window's mask having a class named "wicket-mask-dark"; this may not be the case if you alter the CSS settings used by
ModalWindow
.