取消表单提交
如何使用 GWT 取消表单提交?
我需要在实际提交之前验证表单并处理一些数据。
到目前为止,我做了以下操作,问题是即使取消 SubmitEvent,表单也会提交。
form.addSubmitHandler( new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
if(validate()) {
// i do some processing here
form.submit();
}
else event.cancel(); // submits anyway
}
});
这是 GWT 问题吗?我该怎么办?
编辑:我刚刚发现,如果它是一个在单击时使用 form.submit() 的按钮,则提交事件将被取消。但是,如果单击 SubmitButton,则事件不会取消。
所以我猜这是浏览器的行为。不过,我需要找到方法...
编辑:刚刚发现它只发生在开发模式下,我觉得以前没有尝试过外部开发模式很愚蠢。
How can I cancel a form submission using GWT?
I need to validate the form and process some of the data before actually submitting it.
So far I did the following, the problem is that the form is submitted even if the SubmitEvent is cancelled.
form.addSubmitHandler( new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
if(validate()) {
// i do some processing here
form.submit();
}
else event.cancel(); // submits anyway
}
});
Is this a GWT issue? How should I do?
edit: I just found out that if it was a Button that uses form.submit() on click, the submit event is cancelled. However if a SubmitButton is clicked, the event is not cancelled.
So I guess this is a browser behavior. Still, I need to find way...
edit: just found out that it does only happen in development mode, I feel silly not to have tried outside development mode before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个仅在开发模式下发生的问题
我已报告该问题:http://code.google.com/p/google-web-toolkit/issues/detail?id=5067
It's an issue that only happen in development mode
I have reported the issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=5067