[英]OnSave event fires twice when calling preventDefault after clicking Save and Close button
I've got the following onSave
handler on my form: 我的表单上有以下onSave
处理程序:
onSave: function (executionContext) {
var eventArgs = executionContext.getEventArgs();
var isValid = validate();
if (!isValid) {
eventArgs.preventDefault();
return false;
}
},
To my surprise, onSave
is called twice if preventDefault()
is called, but only when clicking the "Save and Close" button (this behavior doesn't happen when clicking the "Save" button). 令我惊讶的是,如果preventDefault()
,则onSave
被调用两次,但是仅在单击“保存并关闭”按钮时才会发生(单击“保存”按钮时不会发生这种现象)。
Note that you can use the following code as well to reproduce the issue: 请注意,您也可以使用以下代码来重现该问题:
onSave: function (executionContext) {
var eventArgs = executionContext.getEventArgs();
eventArgs.preventDefault();
},
I'd like to know if that's a known issue, and if so, what's your approach to solve it? 我想知道这是否是一个已知问题,如果是,那么您将采用什么方法解决它?
You probably have auto-save turned on (System Setting - Enable auto-save on all forms). 您可能已启用自动保存(系统设置-在所有表单上启用自动保存)。 For auto-save, save is done when you click save and also when you close/navigate from the form. 对于自动保存,在单击“保存”时以及在从窗体中关闭/导航时都将完成保存。 So this is basically by design- one event is triggered because you clicked the "Save" and second is because you also are closing the form (which basically is what "Save and Close" does). 因此,这基本上是设计使然-触发一个事件是因为您单击了“保存”,而第二个事件是因为您还关闭了表单(这基本上就是“保存并关闭”的作用)。
You can check if this is auto-save using something like: 您可以使用以下方法检查是否自动保存:
var eventArgs = econtext.getEventArgs();
if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 2) {
//here you know you are in auto-save
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.