Orbeon xforms window.onbeforeunload 处理程序

Orbeon xforms window.onbeforeunload handler

当有人点击 xform 时,我想实现自定义警报对话框的外观。(不是浏览器使用的对话框)提醒用户并让他有机会选择是否要留下或离开 xforms(cancel/ok 按钮) 这是我的技巧:

<xf:action ev:event="xforms-ready">
<xxf:script>

window.onbeforeunload = function() {
return  ORBEON.xforms.Document.dispatchEvent('fr-form-model','clickout') 
                    } 
</xxf:script>
</xf:action>

这是我的模型和事件处理程序:

<xf:model id="fr-form-model" xxf:expose-xpath-types="true" xxf:external-events="clickout">

<xf:action ev:event="clickout">
<xf:dispatch target="cancel_dialog" name="fr-show"/>
</xf:action>

对话框正确显示,但它并没有留在那里给用户选择要做什么的机会。 1-2 秒后 Xform 关闭,用户无法选择离开或 stay.Any 问题是什么?

...............................更新................................ .....................

Thnx 的答案,至少有可能使用默认对话框的自定义消息吗? (我希望消息使用德语)

基于此,http://wiki.orbeon.com/forms/how-to/logic/alert-users-leaving-a-form-without-saving

我做了这个把戏:

<xxf:script ev:event="xforms-ready">
                window.onbeforeunload = function() {
                    if (ORBEON.xforms.Document.getValue('datastatus') == 'dirty')
                    return "Sie haben nicht gespeicherte Änderungen.";
                    }
            </xxf:script>

模型上方...:

1)

<xf:bind id="data-bind" ref="xxf:instance('fr-persistence-instance')/data-status" name="data"  />

2)

xf:action ev:event="xforms-model-construct-done" >
                <xf:setvalue ref="xxf:instance('fr-persistence-instance')/data-status">clean</xf:setvalue>
            </xf:action>

在视图中:

 <xf:setvalue ev:event="xforms-value-changed" ref="xxf:instance('fr-persistence-instance')/data-status">dirty</xf:setvalue>

................................................

<xf:output bind="data-bind" id="datastatus" />      

在 Ui 中,我可以看到输出 "datastatus" 的值正确地从干净变为脏,但是 window.onbeforeunload 不起作用。(弹出窗口不如果我退出表格就不会出现。有什么想法吗?提前谢谢。

.................................上次更新......... ......................... 有一个取消按钮(退出表单),客户希望此按钮触发与 windows.onbeforenull 默认处理程序触发相同的对话框(如果有未保存的更改),我的意思是浏览器显示的那个。

我试过这样的事情:

<xf:trigger id="cancel-control" bind="cancel-bind">
                                <xf:label ref="$form-resources/cancel/label" />
                                <xf:action ev:event="DOMActivate"  >

                                    <xxf:script if="($calculationsDisabled eq false()) and ((xxf:instance('fr-persistence-instance')/data-status = 'dirty'))">
                                        function() {return "You may lose some unsaved changes.";}
                                    </xxf:script>

                                <xxf:script if="($calculationsDisabled eq true()) or ((xxf:instance('fr-persistence-instance')/data-status = 'clean'))">
                                window.parent.closeIframe();
                                </xxf:script>

                                </xf:action>

                            </xf:trigger>

但它不起作用too.Please请注意下面的自定义对话框方法:

<xf:trigger id="cancel-control" bind="cancel-bind">
                                    <xf:label ref="$form-resources/cancel/label" />
                                    <xf:action ev:event="DOMActivate">
                                        <xf:dispatch target="cancel_dialog" name="fr-show"
                                            if="($calculationsDisabled eq false()) and ((xxf:instance('fr-persistence-instance')/data-status = 'dirty'))" />
                                    </xf:action>

                                    <xf:action ev:event="DOMActivate" if="($calculationsDisabled eq true()) or ((xxf:instance('fr-persistence-instance')/data-status = 'clean'))"  >
                                        <xxf:script>window.parent.closeIframe();</xxf:script>
                                    </xf:action>
                                </xf:trigger>

效果很好,但客户不希望有 2 个不同的对话框windows(浏览器的警告对话框和自定义 "cancel-dialog")。再次提前感谢。

在这种情况下,您不能使用自己的对话框。这是因为如果您的 onbeforeunload returns 除了 nullundefined 之外,浏览器只会停止加载另一个页面,或者 tab/window 被关闭,当发生这种情况时,它会向用户显示自己的对话框。