Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 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 Answer

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...