Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xpages

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?

like image 857
PSolano Avatar asked Jan 17 '23 19:01

PSolano


1 Answers

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?" + "\n" + "\n" +
    "This document may contain unsaved changes." + "\n" + "\n" +
    "Press OK to continue, or Cancel to stay on the current page.")){
        return true;
    }else{
        return false;
    }
} else {
    return true;
}
like image 164
PSolano Avatar answered May 11 '23 16:05

PSolano