Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

xpages - Is there any way to trigger the code behind enableModifiedFlag from CCSJ or SSJS?

If I set enableModifiedFlag property to true on my Custom Control; I see the following code at the bottom of generated Page source.

Everything works fine when user moves away from changed page; they get the alert message of "Unsaved Data"

<script type="text/javascript"> 

function view__id1__id2__id95__id98__id105_clientSide_onclick(thisEvent) {
return validateForm();

}

XSP.attachDirtyUnloadListener("This document may contain unsaved changes.");

XSP.addOnLoad(function() {
XSP.attachEvent("view:_id1:saveActionEventHandler", "view:_id1", "ondirtysave", null, true, 2);
XSP.attachEvent("view:_id1:_id2:_id95:_id98:_id105", "view:_id1:_id2:_id95:_id98:link1", "onclick", view__id1__id2__id95__id98__id105_clientSide_onclick, true, 2);
XSP.attachEvent("view:_id1:_id2:_id95:_id98:_id106", "view:_id1:_id2:_id95:_id98:link2", "onclick", null, true, 2);
XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:businessName11");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:businessName21");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:address11");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:address21");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:city1");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:cbState");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:zipCode1");

XSP.attachDirtyListener("view:_id1:_id2:_id95:_id98:phoneNumber1");

}); 

</script>

I have an Exit button with SSJS that unlocks the document if its locked and makes a context.redirectToPage. The problem is that this button is not triggering the code behind the enableModifiedFlag logic so users leave the page without being prompted if they want to leave with unsaved data.

Is there any way to trigger code behind enableModifiedFlag from this button using CCSJ or SSJS?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By using XSP._isDirty() from CSJS you can get true if any field was modified or false if no changes were done to your form.

So I added this block of code to my button under CSJS to display same default alert from XPages:

if (XSP._isDirty()){
    if (confirm ("Are you sure you want to navigate away from this page?" + "
" + "
" +
    "This document may contain unsaved changes." + "
" + "
" +
    "Press OK to continue, or Cancel to stay on the current page.")){
        return true;
    }else{
        return false;
    }
} else {
    return true;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...