问题是这样的;网页包含多个表单元素,用户可以通过保存按钮更改和保存这些元素,也可以放弃更改。
如果用户尝试在不保存更改的情况下离开页面,我需要一个模式窗口来弹出,询问用户是否想在离开页面之前保存更改。
我将如何检查页面/表单模型自首次加载以来是否已被用户更改,以及当单击任何页面链接时如何启动此检查?
任何回复或建议将不胜感激,
谢谢。
The problem is like this; A webpage contains multiple form elements, which can be altered and saved by the user via a save button, or changes can be discarded.
If the user attempts to navigate away from the page without saving the changes, I need a modal window to pop us asking if the user would like to save the changes before leaving the page.
How would I go about checking to see if the page/form model had been changed by a user since it was first loaded, and how could I initiate this check when any page link is clicked?
Any response or suggestions would be much appreciated,
Thanks.
发布评论
评论(1)
我认为您会寻找一种仅使用 javascript 的解决方案,通常打包为 wicket 行为。
实现取决于您使用的 javascript 库,这里是一些原型代码:
我们将其放入名为 DontLeaveBehavior.js 的文件中 这是
使用此 javascript 文件的行为:
现在这是一个自动将此行为分配给其所有子级的页面它们是文本组件:
最后但并非最不重要的一点是,您的提交按钮当然必须调用 undirty() 。
这些都没有经过测试,因为我现在必须回家与我的妻子和家人共进晚餐。孩子们(当然,这比 wicket 编码更有趣),但它应该可以帮助您入门。
原型特定部分应该可以轻松移植到任何其他 javascript 库,但如果您不知道自己在做什么,则可能不应该在没有库的情况下执行此操作。
编辑:
我创建了一个新版本,可与原型和 mootools 以及 将其发布到我的博客上。此版本仅安装到表单组件,并通过 javascript 自动将其自身附加到子组件。
再次编辑:那里,现在链接正在工作
I think you would be looking for a javascript-only solution, usually packaged as a wicket behavior.
implementation depends on the javascript library you use, here is some prototype code:
We'll put this in a File called DontLeaveBehavior.js
Here's a behavior that uses this javascript file:
Now here's a page that automatically assigns this behavior to all of it's children that are text components:
and last but not least, your submit button has to call
undirty()
of course.None of this has been tested, because I have to go home now to have dinner with my wife & kids (which is even more fun than wicket coding, of course), but it should get you started.
The prototype specific portion should be easily ported to any other javascript lib, but you probably shouldn't do it without a lib if you don't know what you're doing.
Edit:
I have created a new version of this that works with prototype and mootools and posted it on my weblog. This version is only installed to the form component and automatically attaches itself to the children via javascript.
EDIT again: there, now the link is working